Javascript-ajax return value

Source: Internet
Author: User
The ajax request code is as follows: php processing part: Firefox firebug: why can't I print it ???

The ajax request code is as follows:

Php processing:


Firefox firebug:


Why ???

Reply content:

The ajax request code is as follows:

Php processing:


Firefox firebug:


Why ???

I prefer to use it directly.$.post(settings)(Actually prefer direct$.ajax(url, settings). Callback passed$.post()Or$.ajax()The returned promisedone()So that the structure is clear.

$. Post ({url: theurl, dataType: "json", data: {tablename: _ tbname }}). done (function (jo) {// jo is a javascript object // JSON returned from the backend is parsed to the console. log (jo );});

In your way, you can add a parameter "json" after callback to represent the data type.

$.post("http://url/", { tablename: _tbname}, function(data) {}, "json");

Json_encode ($ data, JSON_UNESCAPED_UNICODE)

No error is reported. restart firefox.
PS: Set the response header @ header ("Content-Type: application/json; charset = utf8 ");
Var json = eval (data) can be omitted.
Additionally, it is not safe to use eval. we recommend that you use

var json = jQuery.parseJSON(data);

For chrome (I am really not used to debugging Firefox, so if you are used to it), breakpoint debugging is mostly not implemented. I haven't used Firefox for a long time. I vaguely remember that there were similar problems in the past. This should have been an error in chrome, and there is no error in Firefox. Let's take a look at the breakpoint first. if there is no way to access it, try chrome.

By default, the returned data is a string instead of a json object. Solution 1: specify the return type as json in the request parameters, and parse jquery into an object. Solution 2, deserialize json strings into objects. Example: http://blog.163.com/m13864039...

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.