Get the value returned by the $. Ajax () event in jquery and add the event method.

Source: Internet
Author: User

If you want to get $. the value returned by Ajax () cannot be directly used in success: funciton () {return XX}. To obtain the value of XX, you must use global variables in the script. Use global variables to extract XX values.

Jquery retrieves the return value from the $. Ajax event and adds the event CopyCode The Code is as follows: <HTML>
<Head>
<Title> test jquery to submit dynamic text </title>
<Script language = "JavaScript" src = "jquery. js"> </SCRIPT>
<Script language = "JavaScript">
$ (Function () {// I will not upload the referenced jquery file. Everyone should have it.
$ ("# A1"). Clone (). appendto ("# AP ");
VaR A = ""; // defines global variable;
Txtadd ();
Alert (a); // test whether the global variable has a value;
$ ("# Tall"). Blur (function () {alert ("test") ;}); // Add a blur event that returns the text box from the synchronization event
$ ("# A1"). Blur (function () {alert ("this page event! ") ;}); // Note that the cloned A1 text box does not have a blur event;
Function txtadd (){
$. Ajax ({
Async: false, // synchronous request, because the asynchronous request cannot pass the return value to the global variable;
Type: "Post ",
URL: "autotxt. php ",
Data: {txtid1: 1, txtid2: 2 },
Beforesend: function () {$ ("# TT" loading .html ("loading data... ")},
Success: function (data) {$ ("# TT" cmd.html (decodeuri (data); // autotxt. PHP return value <input name = 'tall' id = 'tall' value = 'dc' maxlength = '6'/>;
A = $ ("# tall"). Val (); // process the returned value to the global variable.
}
});
}
})
</SCRIPT>
</Head>
<Body>
<Form action = "autotxt. php" method = "Post">
<Div id = "TT"> </div>
<Div id = "AP"> </div>
<Input type = "text" id = "A1" name = "A1" value = "test"/>
<Input type = "hidden" id = "OK" name = "OK" value = "OK"/>
<Input type = "Submit" value = "OK"/>
</Form>
</Body>
</Html>

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.