function has 3 parameters, that is, an XMLHttpRequest object, an error message, a captured Error object (optional).
The Ajax event functions are as follows:
function (XMLHttpRequest, textstatus, Errorthrown) {
Usually only one of the Textstatus and Errorthrown contains information
This The options argument passed when invoking this Ajax request
}
ContentType: requires a Str
$. get () returns the same format as a string.Copy codeThe Code is as follows:$. Post ("data. php", $ ("# firstName. val ()"), function (data ){
$ ("# PostResponse" pai.html (data. name );
}, "Json" // sets the type of data to be retrieved, so the obtained data format is json
);3, $. ajax (opiton)
: $. Ajax () is a powerful function that provides many precise control over ajax. For details, see relevant materials.Copy codeThe Code is as follows:$. Ajax ({
Url: "ajax/ajax_selectPicType.aspx ",
D
not need to be converted.
1 $.getJSON("dep.do?p=getAllDep",{x:Math.random()},function(arry){2 for(var i=0;i
Other functions of jquery:
Load Static pages
Load (URL, [data], [callback]);URL (string) URL of the requested HTML pageData (MAP) (optional parameter) Key/value data sent to the serverCallback (callback) (optional) callback function when the request is completed (success is not required)
as "JSONP" or "script" and the type is get. Typically used when local and remote content encodings are different.Three, $.getjson () synchronization settings$.getjson () itself is a method of asynchronous operation that needs to be set to synchronizeAdd $.ajaxsettings.async = false prior to execution; (synchronous execution) returns to $.ajaxsettings.async = True immediately after executing your code, or (
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 longer need to worry about the tangle of Ajax garbled issues. More happily, your JS Code wi
finished executing.Low Level AJAX$.ajax (options) is the syntax for low level AJAX functions.$.ajax provides more functionality than higher-level functions, but it is also more difficult to use.The option parameter sets a Name|value pair that defines URL data, passwords, data types, filters, character sets, timeouts, and error functions.JQuery AJAX Request
Request Description
$ (selector). Load (url,data,callback) loads the remote data into the sel
be used to write the request URL as a "myurl?callback=x" format, so that the program executes the callback function X.$.getjson ("data.php", $ ("#firstName. Val ()"), function (Jsondata) {$ ("#getJSONResponse"). HTML (jsondata.id);} Without setting, the data type is directly obtained as JSON,So you need to use the Jsondata.id method when calling);4, $.ajax ()$.ajax () is a common Ajax package in jquery, wi
],[callback])Url:string type, send request address data: Optional parameter, to be sent Key/value parameter, same as Get,post type of data callback: Optional parameter, load success callback function, with Get,post type callbackJSON is an ideal data transmission format, it can be well fused with JavaScript or other host language, and can be used directly by JS. Using JSON to send "naked" data directly through GET, post, is structurally more reasonable and more secure. As for jquery's
This article focuses on four methods for calling ajax in jQuery: $. get, $. post, $ getJSON, and $ ajax. If you do not have any knowledge about javascript or jquery, or you do not have any idea about ajax, ask du Niang and read this article. When we write ajax programs in javascript, someone suddenly tells you something called
function when the load is successful.
Jquery. getjson provides the callback function, which has three parameters: responsetext, textstatus, and XMLHttpRequest, which respectively represent the content, Request status, and XMLHttpRequest objects returned by the request.
$. Get ("Data/getserviceinfo. aspx ", function (responsetext, textstatus, XMLHttpRequest) {// responsetext: Content returned by the reques
数据alert(data);//这里显示返回的状态alert(state);},"json")3, $.getjson () $.getjson () is specifically for Ajax to get JSON data and is set to support cross-domain calls, the syntax of the format is: Getjson (Url,[data],[callback]) url:string type, Send Request Addressdata: Optional parameter, to be sent Key/value parameter, same as Get,post type of data callback: Optional
the $.getjson () method function in jquery is primarily used to load JSON-encoded data from the server, which uses a get HTTP request. Here's how to use it:$.getjson (URL [, data] [, Success (data, Textstatus, JQXHR)])The URL is a required parameter that represents the address of the JSON data;Data is an optional parameter that is used to send parameters when dat
the server. If not specified, JQuery will automatically be based on the HTTP packet MIME informationReturns Responsexml or ResponseText, and is passed as a callback function parameter, with the available values:"XML": Returns an XML document that can be processed with jQuery.HTML: Returns plain text HTML information, including the script element."Script": Returns plain text JavaScript code. Results are not automatically cached."JSON": Returns the JSO
loading)
"Json": Return JSON data.
"Jsonp": JSONP format. When calling a function in the form of JSONP, such as "myurl? Callback =? "Will jQuery be replaced automatically? For the correct function name to execute the callback function.
"Text": returns a plain text string.
Solution code
Var url = 'HTTP: // 192.168.0.25: 8080/peu/webaction. action? Result = ik format = json jsoncallback =? ';$. Ajax ({Type: "POST ",Url: url,Data :"",DataType: 'jsonp
document, which can be processed by jQuery.
"Html": returns plain text HTML information. The script tag is executed when the dom is inserted.
"Script": returns plain text JavaScript code. Results are not automatically cached. Unless the "cache" parameter is set. ''' Note: ''' during remote requests (not in the same domain), all POST requests will be converted to GET requests. (Because the script tag of DOM will be used for loading)
"Json": Return JSO
JQuery. get ()
JQuery. ajax (): executes asynchronous HTTP (Ajax) requests.
$ (Selector). get (url, data, success (response, status, xhr), dataType)
The simple GET request function replaces the complex $. ajax. You can call the callback function when the request is successful. To execute a fun
When the data is small, the cross-domain is the perfect choice, and the operation is simple and easy to get started.A.com/test.htmlHere I assume there is some data:var formData = Form.serialize ();The jsoncallback here is a callback function name, which is a required parameterWrand ensure that each request is not the same, compatible with IE problemvar url = "http://www.xxx.com/fb/add?wrand=" +math.random () +formdata+ "jsoncallback=?";$.getjson (url,
going to show them in our HTML page.Here, we use .forEach() functions to iterate through the JSON data written to the HTMLL variable.First we define an HTML variable,var html = "";。We then use the .forEach() function to iterate through the JSON data to write to the HTML variable, and finally to display the HTML variables in our page.The code for the entire process is as follows:$.getjson ("/json/cats.json",function(JSON) {varhtml = ""; //please write
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:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.