js 的 ajax 实现
需要或者不需要返回值得ajax函数封装 /** * 原生的ajax封装 * param : * url : * data : * success : * cache : */ var ajax = function(param){ typeof param === "object"; for(var i in param){ param[i] = param[i] === undefined ? "" : param[i] ; } var ajax = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP'); if( typeof param.data === "object" ){ var urli = ""; for (var i in param.data) urli += "&"+i+"="+param.data[i]; } param.url += param.url.indexOf("?") > 0 ? urli : (urli.replace(/^\&(.+)/,"?$1")); ajax.onreadystatechange = function() { if (ajax.readyState === 4 && ajax.status === 200) { param.success && param.success(ajax.responseText); ajax.onreadystatechange = function(){}; }; }; ajax.open('GET', param.url, (param.asy ? 0 : 1)); ajax.send(null); } ajax({ url:"ajax.common.php", data:{"school":"江西"}, success:function(msg){ alert(msg) } })
----走出会议室,只有执行力
解决问题是衡量能力的标准。