In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
这篇文章主要讲解了"ajax请求的方式有哪些",文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习"ajax请求的方式有哪些"吧!
ajax请求方式:1、使用"$.ajax()",可返回其创建的XMLHttpRequest对象;2、通过远程HTTP GET请求载入信息;3、通过远程HTTP POST请求载入信息;4、通过HTTP GET请求载入JSON数据。
本教程操作环境:windows7系统、jquery1.10.2版本、Dell G3电脑。
在jQuery中,AJAX常见的请求方式主要有以下4种:
1、$.ajax()返回其创建的 XMLHttpRequest 对象
$.ajax() 只有一个参数:参数key/value对象,包含各配置及回调函数信息。
如果你指定了dataType选项,那么需要保证服务器返回正确的MIME信息,(如 xml 返回 "text/xml")。
实例:
保存数据到服务器,成功时显示信息。
$.ajax({type: "post",dataType: "html",url: '/Resources/GetList.ashx',data: dataurl,success: function (data) {if (data != "") {$("#pager").pager({ pagenumber: pagenumber, pagecount: data.split("$")[1], buttonClickCallback: PageClick });$("#anhtml").html(data.split("$")[0]);}}});2、通过远程 HTTP GET 请求载入信息
相比于复杂的$.ajax而言,GET请求功能则显得更加简单,请求成功时可调用回调函数。当然如果需要在出错时执行函数,那么还请使用$.ajax。
实例:
$.get("test.cgi", { name: "John", time: "2pm" },function(data){alert("Data Loaded: " + data);});3、通过远程 HTTP POST 请求载入信息
POST请求功能也相对比较简单,请求成功时可调用回调函数。如果需要在出错时执行函数,那么请使用$.ajax请求。
实例:
$.post("/Resources/addfriend.ashx", { "fid": fids, "fname": fnames, "tuid": tuids, "tuname": tunames }, function (data) {if (data == "ok") {alert("添加成功!");}})4、通过 HTTP GET 请求载入 JSON 数据
实例:
$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?tags=cat&tagmode=any&format=json&jsoncallback=?",function(data){$.each(data.items, function(i,item){$("
").attr("src", item.media.m).appendTo("#images");if ( i == 3 ) return false;});}); Thank you for reading, the above is the content of" what are the ways of Ajax request ", after studying this article, I believe that everyone has a deeper understanding of what are the ways of Ajax request, and the specific use needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.