In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "what are the matters needing attention in the use of jQuery.post". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Due to browser security restrictions, most "Ajax" requirements follow a policy of the same origin; that is, data cannot be correctly received from different domains, subdomains, or protocols.
If a jQuery.post () request returns an error code, it quietly fails unless the script calls the global .ajaxError () method. In jQuery 1.5, the .error () method of the jqXHR object returned through jQuery.post () can also be used for error handling.
Example:
Example: requests the test.php page, but ignores the returned result
$.post ("test.php")
Example: request the test.php page and send the url parameter (although the returned result is still ignored).
$.post ("test.php", {name: "John", time: "2pm"})
Example: pass an array of data parameters to the server (although the returned results are still ignored).
$.post ("test.php", {'choices []': ["Jon", "Susan"]})
Example: use Ajax requests to send form data.
$.post ("test.php", $("# testform") .post ())
Example: the data result that Alert requests from test.php (HTML or XML, depending on the result returned).
$.post ("test.php", function (data) {
Alert ("Data Loaded:" + data)
})
Example: Alert requests from test.cgi and sends the data result of the url parameter (HTML or XML, depending on the returned result).
$.post ("test.php", {name: "John", time: "2pm"}
Function (data) {
Alert ("Data Loaded:" + data)
})
Example: get the contents of the test.php, store it in a XMLHttpResponse object, and use the process () JavaScript function.
$.post ("test.php", {name: "John", time: "2pm"}
Function (data) {
Process (data)
}
"xml"
)
Example: Posts to the test.php page and gets contents which has been returned in json format ().
$.post ("test.php", {"func": "getNameAndTime"}
Function (data) {
Console.log (data.name); / / John
Console.log (data.time); / / 2pm
}, "json")
Example: pass a form in ajax and put the result in a div
/ * attach a submit handler to the form * /
$("# searchForm") .submit (function (event) {
/ * stop form from submitting normally * /
Event.preventDefault ()
/ * get some values from elements on the page: * /
Var $form = $(this)
Term = $form.find ('input [name= "s"]') .val ()
Url = $form.attr ('action')
/ * Send the data using post and put the results in a div * /
$.post (url, {s: term}
Function (data) {
Var content = $(data) .find ('# content')
$("# result"). Empty (). Append (content)
}
)
})
This is the end of the content of "what are the precautions for the use of jQuery.post". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.