标签:post callback set something json this status data spec
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);
标签:post callback set something json this status data spec
原文地址:http://www.cnblogs.com/BinBinGo/p/6291635.html