zoukankan      html  css  js  c++  java
  • ajax


    //ajax 连接后端的代码


    var
    xhr = new XMLHttpRequest(); xhr.open("POST"/*传给后台的类型,常用get ,post*/, "TicketGetAllServlet"/*接收的servlet*/, true); xhr.responseType = "json";//响应类型 xhr.setRequestHeader("content-type", "application/x-www-form-urlencoded"); xhr.send("pageSize=" +document.getElementById("pageSize").value+ "& pageNum=" +document.getElementById("pageNum").value);//传给后台的变量 xhr.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) {   var data = this.response;//接收后台返回的值
         //主要的功能
      }
    }


    或者

         var xhr = new XMLHttpRequest()
           var usernamestr = document.getElementById("username").value; var passwordstr = document.getElementById("password").value; xhr.open("post", "login?username="+usernamestr+"&password="+passwordstr/*变量的值也可以在这里写*/, true); xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); xhr.send(); xhr.onreadystatechange = function(){ if (xhr.readyState == 4){ if (xhr.status == 200){ //主要的功能 } } }
    
    
    



  • 相关阅读:
    转基因(转载)
    Diwali
    使用Matplotlib画图
    项目格式规范
    关于Dapper
    JQuery
    javascript封装
    2015年2月16日——作者观点
    2015年2月12日——不懂点
    在VS2013上使用git
  • 原文地址:https://www.cnblogs.com/chenzezhan/p/7756442.html
Copyright © 2011-2022 走看看