If you want to get the value returned in $.ajax (), use it directly in Success:funciton () {return XX} is not possible, to get the value of XX, in the script, to use global variables. Use global variables to elicit the value of XX.
jquery Gets the return value in the $.ajax event and adds the event
Copy Code code as follows:
<title> Test jquery Submit Dynamic text </title>
<script language= "javascript" src= "Jquery.js" ></script>
<script language= "JavaScript" >
$ (function () {//referenced jquery file I don't upload it, everyone should have it.
$ ("#a1"). Clone (). Appendto ("#ap");
var a= ""; Define global variable A;
Txtadd ();
alert (a); Tests whether a global variable has a value;
$ ("#tall"). blur (function () {alert ("Test");}); Add a Blur event that returns a text box from a synchronization event
$ ("#a1"). blur (function () {alert ("This page event!");};/ /Note that the clone out of the A1 text box does not have a blur event;
function Txtadd () {
$.ajax ({
Async:false,//using synchronous requests, because asynchronous requests cannot pass the return value to the global variable;
Type: "Post",
URL: "autotxt.php",
Data:{txtid1:1,txtid2:2},
Beforesend:function () {$ ("#tt"). HTML ("Data Loading ... ")},
Success:function (data) {$ ("#tt"). HTML (decodeURI (data);//autotxt.php return value <input name= ' tall ' id= ' tall ' value= ' DC ' Maxlength= ' 6 '/>;
a=$ ("#tall"). Val (); Handle the return value to the global variable
}
});
}
})
</script>
<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>