JavaScript natively encapsulates an Ajax data request function
Initiate network request body part function urlReques(dict){ /* 封装一个数据请求函数*/ var xhr = new XMLHttpRequest(); var qs = resolveData(dict.data); if(dict.method.toUpperCase() === “GET”){ xhr.open(dict.method,dict.url + ‘?’ + qs); xhr.send() }else if(dict.method.toUpperCase() === “POST”){ xhr.open(dict.method,dict.url); xhr.setRequestHeader(“Content-Type”,”application/x-www-form-urlencoded”); xhr.send(qs); } // 监听请求状态xhr.onreadystatechange = function(){ console.log(xhr.status) if(xhr.readyState === 4 && xhr.status === 200){ var result = JSON.parse(xhr.responseText); dict.success(result); } } } […]
JavaScript natively encapsulates an Ajax data request function Read More »