您的位置:首页 > Web前端 > JQuery

Jquery-Ajax

2015-07-12 15:57 696 查看
原始的Ajax

var xhr=new XMLHttpRequest();

xhr.onreadystatechange //监听事件的响应,改变;

xhr.open("GET", "data/AjaxGetcityInfo.aspx?resultType=html", true);

xhr.send(null);
//可以open(“post/get”,"服务器本地页面或者servlet路径?参数变量=",参数值),然后send()或send(null)
//还可以open(“post/get”,"服务器本地页面或者servlet路径“)然后send(你要传的参数值)

例:

<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>

contentType:要求为String类型的参数,当发送信息至服务器时,内容编码类型默认

为"application/x-www-form-urlencoded"。该默认值适合大多数应用场合。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: