sUrl 请求URL
bAsync true false 是否异步callback 回调函数
function DoAjaxRequest(sUrl,bAsync,callback) { var sRtn = ""; try { var rs = $.ajax({ url: sUrl,async: bAsync,cache: false,complete: function (XMLHttpRequest,textStatus) { if (XMLHttpRequest.readyState == 4 && XMLHttpRequest.status == 200) { if (callback) { callback(XMLHttpRequest.responseText); } } } }); if (!bAsync) { if (rs.readyState == 4 && rs.status == 200) { sRtn = rs.responseText; } } } catch (e) { } return sRtn; }
sUrl 请求URL
cmdstr 提交参数 键值对方式
bAsync true false 是否异步
callback 回调函数
function DoAjaxRequestPost(sUrl,cmdstr,type: "POST",data: cmdstr,textStatus) { if (XMLHttpRequest.readyState == 4 && XMLHttpRequest.status == 200) { if (callback) { callback(XMLHttpRequest.responseText); } } } }); if (!bAsync) { if (rs.readyState == 4 && rs.status == 200) { sRtn = rs.responseText; } } } catch (e) { } return sRtn; }原文链接:https://www.f2er.com/ajax/164895.html