Echo Json_encode back to the JSON object, but the front end gets a string instead of a JSON object

Source: Internet
Author: User
Echo Json_encode Returns a JSON object, but instead of a JSON object, it gets a string in the front-end
Front end use code to submit and process subsequent results

Function del (ID) {
if (Confirm (' Confirm to delete this keyword? ')){
$.post ('./keyword ', {op: ' del ', Id:id},function (Result) {
alert (result); Normal This section should show the Object:object, but now the display is a string
if (Result.code! = 0) {
Alert ("Delete failed! ");
}else{
Location.reload ();
}
});
}
}


The service side uses the following code to return

echo Json_encode (Array ("code" =>0));
Exit


Normally in front of the alert result this variable should be shown as object:object, but this JSON string is now displayed.

Share to: more


------Solution--------------------
$.post ('./keyword ', {op: ' del ', Id:id},function (Result) {...}, ' JSON ');
------Solution--------------------


Function del (ID) {
if (Confirm (' Confirm to delete this keyword? ')){
$.post ('./keyword ', {op: ' del ', Id:id},function (Result) {
alert (result); Normal This section should show the Object:object, but now the display is a string
if (Result.code! = 0) {
Alert ("Delete failed! ");
}else{
Location.reload ();
}
}, "JSON");
}
}


  • 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.