jQuery-ajax-.get,.post方法
2015-02-26 17:40
369 查看
在上一篇中详细介绍了jQuery中ajax局部方法$.load()的使用。下面来介绍两个全局方法$.get(),$.post()的使用。
1、这两个全局方法其实和上一篇中的$.load()方法使用是差不多的。只是多了第四个参数接收的数据类型。
<span style="font-size:14px;color:#FF0000;"><script> $(function(){ /*//直接请求远程的php文件,是以get形式请求的 $("#button").click(function(){ $.get('remote.php',function(response, status, xhr){ //alert(response); //alert(status); //alert(xhr.statusText); $.each(xhr, function(k, v){ $("#box").append(k+'=>'+v+'<br/>'); }) }) })*/ /* //可以在请求的地址中传入参数,也可以在第三个参数上以字符串的形式传入参数 $("#button").click(function(){ $.get('remote.php?username=zhangsan','age=89',function(response, status, xhr){ alert(response); //alert(status); //alert(xhr.statusText); }) })*/ //可以在请求的地址中传入参数,也可以在第三个参数上以对象的形式传入参数 $("#button").click(function(){ $.get('remote.php',{ age:90, username:"zhangsan" },function(response, status, xhr){ alert(response); //alert(status); //alert(xhr.statusText); }) }) //如果需要返回的内容强制转换为我们所需的内容,可以使用第四个参数来接收返回来的内容。如果不传这个从参数,将会智能识别返回来的内容。最好是使用这个参数 /*$("#button").click(function(){ $.get('remote.php?username=zhangsan','age=89',function(response, status, xhr){ alert(response); //alert(status); //alert(xhr.statusText); },'json') })*/ }) </script></span>
上面的这些例子详细讲述了$.get()这个方法的使用,$.post()这个方法的使用方法也是和这个方法是一样的,只是http请求的方法不一样。还有传参数不能直接在URL后面直接加参数,但是也是可以在第二个参数中以字符串的形式或者是以对象的形式传参数。
相关文章推荐
- jquery的get,post和ajax方法的使用
- jQuery的ajax()检验用户名;通过jQuery的load()/get()/post()方法实现;使用XMLHTTPRequest对象来进行AJAX的异步数据交互
- jQuery - AJAX get() 和 post() 方法
- jQuery - AJAX get() 和 post() 方法---非常好的实例
- Jquery中ajax提交表单几种方法(get、post两种方法)
- jQuery教程 - Ajax之$.get()方法和$.post()方法
- jQuery - AJAX get() 和 post() 方法
- jQuery-ajax-.get,.post方法
- jquery实现读取页面load get post ajax的几种代码方法
- jQuery中Ajax的get、post等方法详解
- JQuery 中的ajax的方法 ($.ajax,$.post.$get,$.jgetJSON)
- jQuery 的 .get和.post和.ajax方法IE的兼容问题
- jQuery中$.get、$.post、$.getJSON、$.ajax 方法详解
- Jquery的Ajax中get和post方法的不常见问题
- jQuery调用AJAX时Get和post公用的乱码解决方法实例说明
- jQuery - AJAX get() 和 post() 方法(二十六)
- jquery中get,post和ajax方法的使用小结
- jQuery中$.get、$.post、$.getJSON、$.ajax 方法详解
- 锋利的jQuery读书笔记---jQuery中Ajax--get、post等方法
- 锋利的jQuery读书笔记---jQuery中Ajax--get、post等方法