JQuery Ajax Learning Notes

Source: Internet
Author: User

General usage of a $.ajax

$.ajax ({

Url:url, must have, it specifies the method of sending the request to which controller

Type: ' POST ', selectable, default is get

Data:data, selectable, data sent to the server. is automatically converted to the request string format

Success:function (), selectable, data returned by the server upon successful request

Datatype:datatype selectable, specifies the data type of the expected server response

});

Two-part parameter explanation

The 1:datatype type is string, which is the data type returned by the server, and if not specified, jquery is automatically judged based on the HTTP packet mime information, such as if the XML MIME type is recognized as Xml,json, then a JavaScript object is generated. Scripts execute the script, and then the data returned by the server is parsed and then passed to the callback function, and the following are the most common types:

XML: Returns an XML document that can be processed with jquery.

HTML: Returns plain text HTML information, and the included script tag is executed when it is inserted in the DOM.

Script: Returns plain text JavaScript code that does not automatically cache results. Unless the cache parameter is set. Note: On a remote request (not in the same domain), all post requests are converted to get requests because the script tag of the DOM is used to load.

JSON: Returns the JSON data.

Text: Returns a plain text string.

2:data The main way there are three kinds, HTML splicing, JSON array, form form by Serialize () serialized, by datatype specified, do not specify intelligent judgment.

3:$.ajax can only submit form text, if the asynchronous commit contains <file> upload is not uploaded, you need to use Jquery.form.js $.ajaxsubmit

The 4:$.ajax function returns the XMLHttpRequest object it created. JQuery typically only processes and creates this object internally, but users can also pass a XHR option to deliver a XHR object that they have created. The returned object is usually discarded, but still provides an underlying interface to observe and manipulate the request. For example, the. Abort () on the calling object can suspend the request before the request is completed.

Three: Code exercise:

$.extend ({init:function () {$.ajax () {URL:'/personalmanger/checkmember/getpagedata', type:'Post', data: {"pageindex": PageIndex}, Success:function (JSON) {varJsonobj =Json.parse (JSON); if(Jsonobj.statu = ="OK") {precreatetable (jsonobj); }                if(Jsonobj.statu = ="Nologin") {alert ("you have not logged in, please login! "); Parent.location=Jsonobj.backurl; }                if(Jsonobj.statu = ="nopermission") {alert (jsonobj.msg); Window.location=Jsonobj.backurl; }                if(Jsonobj.statu = ="Err") {alert (jsonobj.msg); }            }        })    }})

JQuery Ajax Learning Notes

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.