All Ajax statuses in jquery

Source: Internet
Author: User

Jquery ajax has been used to deal with the asynchronous problem, which is quite convenient. Recently, due to work project requirements, various States returned from the asynchronously submitted data source need to be processed, now I want to share with you how to learn, not to mention, directly go to the Code:

<SCRIPT src = 'jquery. js'> </SCRIPT> <SCRIPT> $ (function () {$ ("# Starts "). click (function () {$. ajax ({type: 'post', URL: 'ajax. test. PHP ', data: "username = 2", datatype: 'text', cache: false, beforesend: function (XMLHttpRequest) {$ ("# loading "). show () ;}, success: function (MSG) {alert (MSG) ;}, complete: function (XMLHttpRequest, textstatus) {$ ("# loading "). hide () ;}, error: function (data) {If (data. status = "404") {ale RT ('request address error! ');} Else if (data. status = "302") {alert ('webpage connection error');} else if (data. status = "timeout") {alert ("request timed out! ");} Else {alert ('request not responded! Check the network or VPN connection ') ;}}}) ;};}); </SCRIPT> <span id = "starts" style = "cursor: pointer; "> Start </span> | <span id =" loading "style =" display: none; "> loading ...... </span>
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.