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默认参数
$.ajaxSetup({
type: "POST",
url: "test.json",
}) //建立默认参数
4. 解析键值对
$.params({
user: "user1",
email: "user@gmail.com"
}) //对象形式序列化为字符串键值对。