Why does php use ajax to return only numbers to submit the form function & nbsp; subm () {var & nbsp; user & nbsp; $ (# frm ). serialize (); $. ajax ({url: & nbsp; B. php, type: & nbsp; POST, data: user, contentType: Why does app php use ajax to return only numbers?
// Submit the form
Function subm (){
Var user = $ ('# frm'). serialize ();
$. Ajax ({
Url: 'B. php ',
Type: 'post ',
Data: user,
ContentType: "application/json ",
DataType: 'json ',
Async: false,
BeforeSend: function (){
Alert ('error loading PHP document ');
},
Success: function (result ){
Alert (result );
}
});
}
Then, in B. on the php page, write an echo '000000' callback function to execute alert (res) and output 123, but I wrote letters and characters in echo, and he didn't respond, even the box didn't play, I set the page to UTF-8 in B. php also adds a header, but it should be able to return letters and characters. even if it is garbled, a window will pop up. isn't that json transfer problem?
------ Solution --------------------
You have dataType: 'json'
Indicates that the returned string is a json string.
Obviously, non-numeric strings fail to be parsed because quotation marks are missing.
------ Solution --------------------
Your dataType is in json format, and json data is returned in php.
You can use json_encode () to return a result.