做個記錄
有時候只是做簡單的 GET / POST 其實可以不需要依靠 jQuery
function createRequest2() { var request = null; try { request = new XDomainRequest(); } catch (othermicrosoft) { try { request = new XMLHttpRequest(); } catch (othermicrosoft) { try { request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (othermicrosoft) { try { request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (failed) { request = NULL; } } } } return request; }
用法如下:
var request2 = createRequest2(); if (request2 != null) { var url = "http://www.xxx.com/"; request2.open("GET", url, true); request2.onreadystatechange = function () { if (request2.readyState == 4) { if (request2.status == 200) { if (request2.responseText) { // 進行的動作 } } else { // 失敗的動作 } } }; request2.send(); }
更詳細的請參考另外一篇文章 有的時候其實真的不需要用到 jQuery