JQuery-1.9.1 source code analysis series (16) ajax-response data processing and api sorting, jquery-1.9.1ajax
After ajax receives a request response, it mainly performs two processes: obtaining the response data and converting the data using the type converter.A.
Conversion from: understand $. Get, $. Post, $. getjson, and $. Ajax usage in jquery.
When we write Ajax programs in Javascript, someone suddenly tells you something called jquery, which will tell you how happy it is not directly with httprequest, at the same time, you no l
The role of the framework is to simplify what we do, but it is flexible. Jquery is the mainstay of the js framework. It is flexible and powerful.Jquery encapsulates ajax perfectly, not to mention its powerful underlying ajax functions, but its upper-layer get, post, getscript, and getJson functions are quite handy for
Jquery.get () method:
$.get (Url,data,success (RESPONSE,STATUS,XHR), DataType)
This function is shorthand for the Ajax function, which is equivalent to:
$.ajax ({
url:url,
data:data,
success:success,
datatype:datatype
});
The return data passed to the success callback function differs depending on the MIME typ
Solve, how to solve it? Another domain name walk is OK, but this domain name does not go, front-end code is as follows:
The backend code is as follows:
Reply content:
Solve, how to solve it? Another domain name walk is OK, but this domain name does not go, front-end code is as follows:
The backend code is as fo
When we write the Ajax program with JavaScript "Happy", suddenly someone tells you there is a thing called jquery, it will tell you not directly and HttpRequest is how happy, at the same time you no longer need to worry about the tangled Ajax garbled problem, Happier is your JS code will be greatly simplified, after re
HTTP status Code and its definition parsing AJAX capture callback error reference
The status line contains the HTTP version, status code, and a brief description of the status
HTTP status code and definition parsing Ajax capture callback error reference
The status line contains the HTTP Version, status code, and brief descriptions corresponding to the status
json, the returned format is json, and $. the format returned by get () is the same as that returned by get.
JQuery. post (url, data, success (data, textStatus, jqXHR), dataType)
$.ajax({ type: 'POST', url: url, data: data, success: success, dataType: dataType});
(XMLHttpRequest, textstatus) {This The options for this AJAX request}ContentType String (default: "application/x-www-form-urlencoded") the content encoding type when sending information to the server. The default values are suitable for most applications.Data Object,String to send data to the server. is automatically converted to the request string format. The GET request will be appended to the URL. View
There is a problem. The code in the middle of the page finds that there is no ID. how can I get the 404 status code returned? As you know, output 404 depends on the header. Generally, the first header (404... similar.
However, when some logic code is encountered, the client
This article turns from: http://jun1986.iteye.com/blog/1399242 thank him for sharing$.post, $.get is a simple method, if you want to deal with complex logic, still need to use the Jquery.ajax ()I. GENERAL format of $.ajax$.ajax ({Type: ' POST ',URL: url , Data: data , Success: success , DataType: dataType });Second, the parameter description of $.ajaxParameter
. Here jQuery has helped us solve the problem, and we can use $. ajax for bytes;
In callback functions, the old writing method requires writing
xhr.onreadystatechange = function(data) {if (xhr.readyState == 4 xhr.status == 200) {
But in jQuery's writing method, a success: function (data) {is enough. Is it much easier?
Attach the old ajax Request
First, let's look at an ajax request instance:
Appendix: code in SQL. php
Execution result:
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131229/1223553460-0.jpg "title =" 2013-11-28_105125.jpg "alt =" 105617217.jpg"/>
Note: Only One callback function can be used for one page at a time (how to distinguish between them ?).
I,$. Get
In jQuery, The get () function of ajax is used to read the page.
First, we will introduce the get () function:
Url, [data], [callback], [type]
Parameter description:Url: the URL of the page to be loadedData: Key/value parameter to be sent.Callback: callback function when the load is successful.Type: The returned conten
This article mainly introduces the ajax get () method usage in jQuery, and analyzes in detail the functions, definitions, and usage skills of the get () method in the form of examples, if you need it, refer to the example in this article to describe the ajax
A simple example of how jquery uses Ajax to get data across domains
var WebMethod = "Http://localhost:54473/Service1.asmx/HelloWorld";
JQuery.support.cors = true;
Didn't add this sentence always hint no transport, I didn't go to deep thought.
$.ajax
({
type: POST,
contentType: "appli
There are two common approaches to browser-side cross-domain access:1, through the Ajax of jquery cross-domain, which is actually used in the JSONP way to achieve.JSONP is an abbreviation for English json with padding. It allows script tags to be generated on the server side to return to the client, that is, to dynamically generate JavaScript tags and to read data in the form of JavaScript callback.HTML
a variable name, followed by a value to be passedTen //"Age ": "Youage", One //" Sex": "Youage", A //"Other" : " Other" - }, -Successfunction(data) {//callback result, if successful the if(Data.status = = 0) {//Judging Status Codes - //Refresh -$ ("#easyuiDatagrid"). DataGrid ("Reload")); - } + }, -Failurefunction(Result) { +Parent.$.messager.show ({title: "Hint", msg: "Failed, please co
Here to achieve the function is: by scanning Code micro-letter public number with parameters of two-dimensional code, to log on to the site.
But obviously, if Ajax uninterrupted request server, this will aggravate the load of the server, so this example uses JS setinterval to periodically invoke the implementation of an AJAX
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
[email protected]
and provide relevant evidence. A staff member will contact you within 5 working days.