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){ //主要的功能 } } }
    
    
    



  • 相关阅读:
    uva 11294 Wedding
    uvalive 4452 The Ministers’ Major Mess
    uvalive 3211 Now Or Later
    uvalive 3713 Astronauts
    uvalive 4288 Cat Vs. Dog
    uvalive 3276 The Great Wall Game
    uva 1411 Ants
    uva 11383 Golden Tiger Claw
    uva 11419 SAM I AM
    uvalive 3415 Guardian Of Decency
  • 原文地址:https://www.cnblogs.com/chenzezhan/p/7756442.html
Copyright © 2011-2022 走看看