zoukankan      html  css  js  c++  java
  • AJAX请求

    使用纯粹的JavaScript创建一个AJAX请求:

    function loadXMLDoc() {

        var xmlhttp;

     

        if (window.XMLHttpRequest) {

            // code for IE7+, Firefox, Chrome, Opera, Safari

            xmlhttp = new XMLHttpRequest();

        } else {

            // code for IE6, IE5

            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

        }

     

        xmlhttp.onreadystatechange = function() {

            if (xmlhttp.readyState == 4 ) {

               if(xmlhttp.status == 200){

                   alert("success");

               }

               else if(xmlhttp.status == 400) {

                  alert("error 400")

               }

               else {

                   alert("something broke")

               }

            }

        }

     

        xmlhttp.open("GET", "test.html", true);

        xmlhttp.send();

    }

    来源: Stack Overflow

    而使用jQuery创建AJAX请求:

    $.ajax({

        url: "test.html",

        statusCode: {

        200: function() {

        alert("success");

        },

        400: function() {

        alert("error 400");

        }

        },

        error: function() {

        alert("something broke");

        }

    });

  • 相关阅读:
    bzoj 1053
    bzoj 1004 组合
    字符串哈希
    bzoj 1015 并查集
    bzoj 1003 最短路+dp
    HDU 4352 数位dp
    bzoj 1879 状压dp
    codeforces 55D 数位dp
    Codeforces 830B
    组合计数 && Stirling数
  • 原文地址:https://www.cnblogs.com/papajia/p/4498200.html
Copyright © 2011-2022 走看看