Why does php use ajax to return only numbers?

Source: Internet
Author: User
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.

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.