An example of this paper is to analyze the wrapping problem of the return value of Ajax asynchronous commit data. Share to everyone for your reference, specific as follows:
The previous analysis describes the JavaScript based on Ajax callback function transfer parameters and "IE browser and FF browser on the value of the ajax transfer parameter is Chinese," learning the Ajax callback function to participate in different browsers to deal with Chinese garbled problem method. Here's an analysis of the processing techniques of the wrapping problem in the Ajax asynchronous commit return value.
Background information:
The features you need to implement are: Select a category in the dropdown box, submit to PHP to return the member names under the category according to the selected category, and return the names of the members to the textarea in the form of a newline.
HTML code:
<form action= "Setduty.php?action=add" method= "post" name= "Setform" id= "Setform" >
<p> <label> Type:</label>
<select name= "type" id= "Typeduty" >
<option value= "-1" > Selection type </option>
<option value= "1" > Duty chief </option>
<option value= "2" > Duty director </option>
<option Value= "3" > on duty </option>
</select>
</p>
<p class= "Opertext" >
< Label> member:</label> <textarea name= "names" id= "names" cols= "a"
rows= "ten" ></textarea>
</p>
JQuery Code:
$ (document). Ready (function () {
$ ("#typeduty"). Change (function () {
var type = $ ("#typeduty"). Val ();
$.post ("setduty_do.php",
{
' cid ': type,
},function (data,status) {
NewData = data.replace (/\r\n/g, ' ');
$ ("#names"). HTML (newdata);
});
});
PHP Code:
if ($type) {
switch ($type) {case
"1":
$arrs = Getchieflist ();
break;
Case "2":
$arrs = Getdirectlist ();
break;
Case "3":
$arrs = Getattendantlist ();
break;
Default: Break
;
}
$arr _names = "";
foreach ($arrs as $arr) {
if (strlen ($arr [1]) >2) {
$arr _names.= $arr [1]. " \ n ';
}
}
echo $arr _names;
}
The value returned in the PHP code is directly with a newline "\ n", and the line-break symbol for IE and FF in textarea is "\ n", and the processing return value of JQuery is noted, using
Copy Code code as follows:
NewData = Data.replace (/\r\n/g, ");
Handles the returned results, which are used to remove the first line break symbol, and the value returned by Ajax automatically comes with a newline. This is the AJAX itself.
I hope this article will help you with Ajax programming.