Jquery-Ajax

原始的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"。该默认值适合大多数应用场合。编码

相关文章
相关标签/搜索