JQuery AJAX

1. 加载

$("input").click(function () {

$("#box").load("test.html", ".my");   //一部加载数据到#box里面,  第二个参数筛选加载的内容

$("#box").load("test.html",{"url": 'yuck'});  //以POST方式提交

}, function(reponse, status, xhr) {

console.log(reponse, status, xhr);

console.log(xhr.status, xhr.responseText, xhr.statusText);

});

2. get和post

$("input").click(function (){

$.get("test.html", "url=ycku", function (response, status, xhr) {    //字符串键值对传参

$("#box").html(test.html);

});

});

$("input").click(function (){

$.get("test.html", {url:"ycku"}, function (response, status, xhr) {   //字典形式传参

$("#box").html(test.html);

});

});

$("input").click(function (){

$.post("test.html", "url=ycku", function (response, status, xhr) {   //字符串形式传参

$("#box").html(test.html);

})

});

$("input").click(function (){

$.post("test.html", {url:"ycku"}, function (response, status, xhr) {  //字典形式传参

$("#box").html(test.html);

})

});

$("input").click(function (){

$.get("test.json", "url=ycku", function (response, status, xhr) {   //返回json对象

$("#box").html(reponse[0].url);

})

}, "json");

$("input").click(function (){

$.getJSON("test.json", "url=ycku", function (response, status, xhr) {

$("#box").html(reponse[0].url);

})

});

$("input").click(function (){

$.getScript("test.js");  //加载脚本并执行。

});

3. 底层ajax方法
$.ajax({type: "POST", 
url: "test.json",
data: $("form").serialize(),   //序列化表单为键值对字符串,还可以使用$("form").serializeArray() 序列化为json对象
success: function(response, status, xhr) {
$("#box").html(response[0].value);
}
});

3. ajax默认参数

$.ajaxSetup({

type: "POST",

url: "test.json",

})  //建立默认参数

4. 解析键值对

$.params({

user: "user1",

email: "user@gmail.com"

})  //对象形式序列化为字符串键值对。









评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值