Echo Json_encode Returns a JSON object, but instead of a JSON object, it gets a string in the front-end

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


Reply to discussion (solution)

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

Function del (ID) {      if (Confirm (' Confirm to delete this keyword? ') {$.post ('./keyword ', {op: ' del ', Id:id},function (Result) {alert (result);//Normal This part should show 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.