Jquery+ajax request with return value code _jquery

Source: Internet
Author: User

Now more popular using jquery Ajax to achieve some no refresh request effect, this section provides a very simple example of code for your reference, I hope to be able to bring some help to the needs of friends, the code is as follows:

<script type= "Text/javascript" >/* Request Ajax with return value, and pop-up reminder box to remind--------------------------------------------------* * function Getajax (url,parm,callback) {$.ajax ({type: ' Post ', DataType: "Text", Url:url, Data:parm, cache:f 
  Alse, Async:false, Success:function (msg) {callBack (msg);  }}}/* Delete/*url: Represents the request path--------------------------------------------------/function DeleteData (url,id) {var 
 Parm= ' active=del&id= ' +id; if (id==undefined| | 
 id== "") {showalertmsg (' Please select a row to delete '); } else {showconfirmmsg ("This operation is not recoverable, are you sure you want to delete it?") ", function (r) {if (R) {Getajax (Url,parm,function (RS) {if (parseint (RS) >0) {Showove Ralertmsg ("Delete succeeded!") 
     ", 2000,4); else if (parseint (rs) = = 0) {showoveralertmsg ("This data is associated and cannot be deleted!") 
     ", 2000, 3); else {showoveralertmsg (delete failed!) 
     ", 2000, 5); }}}})}//Remove function Deleteonclick () {deletedata (' sysmenu_list.aspx ', menu_ID);

 } </script>

Async is an abbreviation for asynchronous[asynchronous], which is a bool value default of TRUE. When Async is true, the AJAX request is executed down regardless of whether it is complete or not. The synchronization request temporarily locks the browser and does not perform any action when the request is executing.

Describe the next two days to achieve the function, to determine whether a data database exists, if there is a return error, does not exist can be filled out and submitted. The code is as follows:

Iscompany:function (name) {
  var flag = 0;
  if (name = = =) {return
    false;
  } else{
    $.ajax ({
      type: "POST",
      URL: '/checkcompany/name/' + name,
      cache:false,
      success:function ( Data) {return
         data > 0 false:true
      }}
  }

Through the code above, has been unable to correctly respond to the database has been the name. With the next global variable, the async (default is True) is asynchronously converted to synchronization, and the Ajax return value is successfully obtained. The code is as follows

Iscompany:function (name) {
  var flag = 0;
  if (name = = =) {return
    false;
  } else{
    $.ajax ({
      type: "POST",
      URL: '/checkname/name/' + name,
      cache:false,
      async:false,
      Success:function (data) {
        flag = data;}}
    )
  }
  Return flag > 0? false:true;
}

The above is the use of the Ajax in jquery to submit data and then by the Web site backstage to the data we submitted to return the content of the data, we hope to learn Ajax help.

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.