您当前的位置: 首页 > 学无止境 > 网站建设 网站首页网站建设
jquery-ajax全局方法get与post
发布时间:2016-04-03 17:03:06编辑:雪饮阅读()
Jquery-ajax全局方法get:
$("input").click(function(){
$.get("test.php?url=ycku",function(response,status,xhr){$("#box").html(response)});
});
通过第二个参数字符串形式的键值对传get参数:
$("input").click(function(){
$.get("test.php",'url=ycku',function(response,status,xhr){$("#box").html(response)});
});
通过第二个参数对象形式的键值对传get参数:
$("input").click(function(){
$.get("test.php",{url:'yck',url2:'yck2'},function(response,status,xhr){$("#box").html(response)});
});
Jquery-ajax全局方法post:
与get不同的是get的第一种传参方式,get的另外两种传参方式均与post相同
Jquery-ajax的第四个参数为type,该参数有四个选项值:html,text,xml,json
如果是纯文本内容设置xml或json则会无法获取到返回结果
返回xml若设置html则会将xml源代码呈现到浏览器中
$("input").click(function(){
$.get("test.xml",function(response,status,xhr){alert(response)},'html');
});
查找请求中的xml节点值:
$.get("test.xml",function(response,status,xhr){alert($(response).find('root').find('url').text())},'xml');
获取json数据:
$.get("test.json",function(response,status,xhr){alert(response[0].url)},'json');
Get与post方式请求对比:
Jquery-ajax的json专用获取函数:
$.getJSON("test.json",function(response,status,xhr){alert(response[0].url)});
Jquery-ajax的script专用获取函数:
$.getScript("test.js");
关键字词:jquery,ajax,get,post
上一篇:jquery-ajax入门
下一篇:jquery-ajax表单序列化