原始的Ajaxjavascript
var xhr=new XMLHttpRequest();html
xhr.onreadystatechange //監聽事件的響應,改變;java
xhr.open("GET", "data/AjaxGetcityInfo.aspx?resultType=html", true);ajax
xhr.send(null);
//能夠open(「post/get」,"服務器本地頁面或者servlet路徑?參數變量=",參數值),而後send()或send(null)
//還能夠open(「post/get」,"服務器本地頁面或者servlet路徑「)而後send(你要傳的參數值)json
例:服務器
<script type="text/javascript">
var show = function () {
function initCategory() {
$.ajax({
type: "POST",
url: "Admin_sever/WebService/GetAllCategory",
contenType: "application",
dataType: "json",
data: "{}",
success: function (r)
{
var menu_content = r.d;
console.log(menu_content);
},
error: function () { }
});
}
return {
init: function () {
show();
}
}
}();
show.init();
</script>app
contentType:要求爲String類型的參數,當發送信息至服務器時,內容編碼類型默認post
爲"application/x-www-form-urlencoded"。該默認值適合大多數應用場合。編碼