Jquery.ajax () Access interface __jquery

Source: Internet
Author: User
Tags serialization

jquery is very well encapsulated in asynchronous submissions and is very cumbersome to use Ajax directly, and jquery simplifies our operations without considering the surprise of browsers.

Recommend a good jquery Ajax instance article, forget to go to see, the address is: http://www.cnblogs.com/yeer/archive/2009/07/23/1529460.html and http:// www.w3school.com.cn/jquery/

$.post, $.get is a simple method, if you want to deal with complex logic, still need to use the Jquery.ajax ()

General format of $.ajax

$.ajax ({

Type: ' POST ',

Url:url,

Data:data,

Success:success,

Datatype:datatype

});

Description of parameters describing parameters of $.ajax

Url Necessary. Specify which URL to send the request to.
Data Optional. The mapping or string value. Specify the data to be sent to the server along with the request.
Success (data, Textstatus, JQXHR) Optional. The callback function to execute when the request succeeds.
DataType

Optional. Specify the data type of the expected server response.

The default execution of intelligent judgments (XML, JSON, script, or HTML).

third, $.ajax need to pay attention to some places:

1.data main methods are three kinds, HTML splicing, JSON array, form form by serialize () serialization, by datatype specified, do not specify intelligent judgment.

2.$.ajax only submits form in text mode, if the asynchronous commit includes <file> uploads is passed over, need to use Jquery.form.js $.ajaxsubmit


Four, $.ajax my practical application example JS Code   //1.$.ajax Asynchronous request    Var aj = $.ajax with JSON data ( {          url: ' productmanager_reverseupdate ',//  jump to  action          data:{                   selRollBack : selRollBack,                   seloperatorscode : seloperatorscode,                    provincecode : provincecode,                   pass2 : pass2         },          type: ' Post ',         cache: false,   &nbsp     datatype: ' JSON ',         success:function (data)  {             if (data.msg == "true"   ) {                 // view (The modification was successful.) ");                 alert (" modified successfully. ");                  Window.location.reload ();             }else{                  view (data.msg);              }           },          error : function ()  {& nbsp;              // view ("Exception"). ");               alert (" Exception "). ");          }    });        //2.$.ajax Serialized table contents as strings of asynchronous requests    Function notips () {          var formparam = $ ("#form1"). Serialize ()//Serialization table contents as String           $.ajax ({             type: ' Post ',                  url: ' Notice_ Notipsnotice ',             data:formParam,              cache:false,            &Nbsp; datatype: ' JSON ',             success: function (data) {             }      &NBSP;&NBSP;&NBSP;&NBSP});    }          //3. Asynchronous request for $.ajax stitching URL    var yz=$.ajax ({          type: ' Post ',          url: ' validatepwd2_checkpwd2?password2= ' +password2,           data:{},           cache:false,          datatype: ' JSON ',           success:function (data) {                if ( data.msg == "false"  )  //server returns False, Change the value of ValidatePassword2 to PWD2Error, this is asynchronous, need to consider return time                {                      Textpassword2.html ("<font color= ' red ' > Business password is incorrect.) </font> ");                     $ ("#validatePassword2"). Val ("Pwd2error");                     checkPassword2 = false;                      return;                }            },            error:function () {}    });        //4.$.ajax asynchronous request for data splicing    $.ajax ({           url: ' <%=request.getcontextpath ()%>/kc/kc_checkmernameunique.action ',           type: ' Post ',          data: ' MerName= ' +values, &nb

Related Article

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.