zoukankan      html  css  js  c++  java
  • 取得 Ajax 返回参数

    1  ajax 函数,p1 为正常参数
    
        function ExecWebFunction(callback,p1) {
         
            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                datatype: "json",
                url: URL,
                data: ajaxdata,
                beforeSend: function (XMLHttpRequest) {
                    //Specifying this header ensures that the results will be returned as JSON.
                    XMLHttpRequest.setRequestHeader("Accept", "application/json");
                },
                success: function (data, textStatus, XmlHttpRequest) {
                    //成功执行语句
                    if (typeof callback === 'function') {
                        callback("SUCCESS", data.d);
                    }
                    getresult(data.d);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    //错误执行语句
                    if (typeof callback === 'function') {
                        callback("ERROR", textStatus);
                    }
    
                }
            });
        }
    
    2 callback 函数--用来处理上面执行之后的事务.
    
        function callback(info, result) {
            if (info == "SUCCESS") {
                //do somethings
            }
            else {
              //do somethings
            }
        }
    
    3 调用方式如下:
    ExecWebFunction(callback,p1);
  • 相关阅读:
    【日语】日语学习计划(转载)
    【日语】日语商务情景口语
    Nop常用知识点
    c#版在pc端发起微信扫码支付
    nopcommerce 常用属性验证
    @codeforces
    @codeforces
    @codeforces
    @codeforces
    @codeforces
  • 原文地址:https://www.cnblogs.com/BinBinGo/p/6291635.html
Copyright © 2011-2022 走看看