The jquery ajax request parameters and usage details

url: Requirements of type String parameter (the default address of this page) address of the request.

type: type String parameter requirements, request method (POST or get) defaults to get. Note that other methods http request, and put e.g.

      delete can be used, but only part of the browser supports.

timeout: Number requirements for the type of the parameter, setting request time (in milliseconds). This setting is provided to cover the global $ .ajaxSetup () method

         Home.

async: Boolean type parameter requirements, default set to true, all requests are asynchronous requests.

       If you need to send a synchronization request, set this option to false. Note that the synchronization request will lock the browser, the user must wait for other operations

       To be completed before the request can be executed.

cache: requirements for the Boolean type parameter defaults to true (as when dataType Script, the default is false).

       Set to false will not load request information from the browser cache.

data: Object requirements or parameters of type String, the data sent to the server. If you have not a string, the string will be automatically converted to grid

      formula. get request will be appended to the url. Prevent this automatic conversion, you can view processData options. Object must be a key / value format

      Type, for example, {foo1: "bar1", foo2: "bar2"} is converted to & foo1 = bar1 & foo2 = bar2. If the array, JQuery will automatically be different

      Values ​​correspond to the same name. For example {foo: [ "bar1", "bar2"]} is converted to & foo = bar1 & foo = bar2.

dataType: String requirements for the type of parameters, the expected data type returned by the server. If not specified, JQuery will automatically according to the http package mime

          Returns information responseXML or responseText, and passed as a callback function parameters.

          Available types are as follows:

          xml: returns an XML document, available JQuery process.

          html: Returns the HTML plain text information; script tag contained performs when inserted DOM.

          script: return plain text JavaScript code. It does not automatically cached results. Unless the cache parameter sets. Note that the remote request

                  When (not under the same domain), all post requests are converted to get the request.

          json: returns JSON data.

          jsonp: JSONP format. When using the form SONP call functions, such as myurl? Callback = ?, JQuery will automatically replace a post

                "?" Is the correct name of the function to execute the callback function.

          text: Returns the plain text string.

beforeSend: Function type parameter is required, the function may be modified before sending a request XMLHttpRequest object, such as adding custom

            HTTP header. Returns false if the beforeSend can cancel the ajax request. The XMLHttpRequest object is the only reference

            number.

            function(XMLHttpRequest){

               this; // passed when calling ajax request options for this parameter

            }

complete: Function requirements for the type of parameters, request a callback function to call when completed (requests are called when the success or failure).

          Parameters: XMLHttpRequest object and a type description string successful request.

          function(XMLHttpRequest, textStatus){

             this; // passed when calling ajax request options for this parameter

          }

success: Function requirements for the type of parameters, the callback function to call when the request is successful, there are two parameters.

         (1) returned by the server, and performs data processing in accordance with the dataType parameter.

         String (2) described state.

         function(data, textStatus){

            // data may be xmlDoc, jsonObj, html, text, etc.

            this; // passed when calling ajax request options for this parameter

error: Function type parameter is required, the function is called when the request fails. This function takes three parameters, i.e., XMLHttpRequest object, wrong

       False information, error object captured (optional).

       ajax event functions as follows:

       function(XMLHttpRequest, textStatus, errorThrown){

          // Under normal circumstances textStatus and errorThrown only one of which contains information

          this; // passed when calling ajax request options for this parameter

       }

contentType: String Type parameter is required, when the transmission information to the server, the content default encoding type

             Is "application / x-www-form-urlencoded". The default value is suitable for most applications.

dataFilter: Function type parameter requirements, Ajax returned to the original data preprocessing functions.

            Provide data and type two parameters. data is the raw data returned by Ajax, type is provided when calling jQuery.ajax

            dataType parameter. The value returned by jQuery further processing.

            function(data, type){

                // returns the processed data

                return data;

            }

global: Boolean requirements for the type of argument, the default is true. It indicates whether to trigger a global ajax event. Set to false will not trigger the global

        ajax event, ajaxStart or ajaxStop ajax be used to control a variety of events.

ifModified: Requirements for the Boolean type parameter, the default is false. To obtain new data only when the server data changes.

            Server data change judgment based on the Last-Modified header information. The default value is false, ignoring the header information.

jsonp: requirements parameter of type String, rewrite in the name of a callback function jsonp request.

       This value is used to replace the "callback =?" This URL GET or POST request parameter in the "callback" section, e.g.

       {Jsonp: 'onJsonPLoad'} will cause "onJsonPLoad =?" To the server.

username: String type parameter requirements, in response to the user name for HTTP access authentication request.

password: String type parameter requirements, in response to a password authentication HTTP access request.

processData: Requirements for the Boolean type parameter, the default is true. By default, data transmission will be converted to an object (from a technical point

             String is not speaking) to match the default content type "application / x-www-form-urlencoded". If you want to send DOM

             Tree information or other information do not want to convert, set to false.

scriptCharset: String type parameter requirements, only when the request is dataType "jsonp" or "script", and the type is GET

               It will be used to modify the mandatory character set (charset). Not normally used in both local and remote content encoding.

 

Case Code:

$(function(){

    $('#send').click(function(){

         $.ajax({

             type: "GET",

             url: "test.json",

             data: {username:$("#username").val(), content:$("#content").val()},

             dataType: "json",

             success: function(data){

                         $ ( '# ResText') empty ();. // emptied of all content inside resText

                         was html = ''; 

                         $.each(data, function(commentIndex, comment){

                               html += '<div class="comment"><h6>' + comment['username']

                                         + ':</h6><p class="para"' + comment['content']

                                         + '</p></div>';

                         });

                         $('#resText').html(html);

                      }

         });

    });

});



// POST request
function the doPost (URL, Data, EUID, Key, O, Success) {
    $ .ajax ({
        type: "the POST",
        URL: URL,
        Data: the JSON.stringify ({
            S: security.encrypt (the JSON. the stringify (Data), Key),
            O: O,
            U: EUID,
            K: security.genVldCode (EUID, Key)
        }),
        contentType: "file application / JSON; charset = UTF-. 8", the text // request
        crossDomain: true, // whether cross-domain
        success: success // callback request success
    });
}

Guess you like

Origin www.cnblogs.com/Jeely/p/10977609.html