In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
In this issue, Xiaobian will bring you about how to understand the ajax-get () method in jQuery. The article is rich in content and analyzed and described from a professional perspective. After reading this article, I hope you can gain something.
Use the get, post, and ajax methods in jquery to pass data to the server
jQuery Ajax Reference Manual
examples
Use AJAX GET requests to change the text of div elements:
$("button").click(function(){ $.get("demo_ajax_load.txt", function(result){ $("div").html(result); });});
give it a try
definition and use
The get() method loads information via a remote HTTP GET request.
This is a simple GET request function to replace the complex $.ajax. Callback functions can be invoked when the request is successful. If you need to execute a function on error, use $.ajax.
syntax
$(selector).get(url,data,success(response,status,xhr),dataType)
详细说明
该函数是简写的 Ajax 函数,等价于:
$.ajax({ url: url, data: data, success: success, dataType: dataType});
根据响应的不同的 MIME 类型,传递给 success 回调函数的返回数据也有所不同,这些数据可以是 XML root 元素、文本字符串、JavaScript 文件或者 JSON 对象。也可向 success 回调函数传递响应的文本状态。
对于 jQuery 1.4,也可以向 success 回调函数传递 XMLHttpRequest 对象。
示例
请求 test.php 网页,忽略返回值:
$.get("test.php");
更多示例
例子 1
请求 test.php 网页,传送2个参数,忽略返回值:
$.get("test.php", { name: "John", time: "2pm" } );
例子 2
显示 test.php 返回值(HTML 或 XML,取决于返回值):
$.get("test.php", function(data){ alert("Data Loaded: " + data);});
例子 3
显示 test.cgi 返回值(HTML 或 XML,取决于返回值),添加一组请求参数:
$.get("test.cgi", { name: "John", time: "2pm" }, function(data){ alert("Data Loaded: " + data); });
jquery ajax 的 $.get()用法详解
js文件
$(document).ready(function(){ $("form").submit(function(event) {event.preventDefault()})//取消submit的默认行为 $("form input[type='submit']").click(function(){ var url = $('form').attr('action'); // 取Form中要提交的链接 var param = {}; // 组装发送参数 param['name'] = $('form input[name=name]').val(); param['age'] = $('form input[name=age]').val(); $.get(url, param, function(dom) { $('div.get').append(dom) }) ; // 发送并显示返回内容 });})
html文件
Name: Age: 这是ajax的get方法
php文件
error_reporting(0); if($_GET["name"]=="kitty"){ $name= "you are the lucky";}else$name=$_GET["name"];$age=$_GET["age"];echo " ".$name." ".$age."";上述就是小编为大家分享的如何理解jQuery中ajax - get()方法了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注行业资讯频道。
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.