Question about jquery getting json data from the server

Source: Internet
Author: User
The same ajax method requests different json data returned by php. it is strange that one can have a value without a value. The following is the processing of the returned data received by my ajax method {code...}. I am very sure that obj is actually in json format. However, alert has always been the json data returned by different php requests using the same ajax method. it is strange that one can have a value without a value. The following shows how my ajax method processes the returned data.

function getUpList(_url, _u, _p){    $.ajax({        type:"GET",        data:$.param({uid:_u, page:_p}),        url:_url,        dataType:'json',        success:function(obj){            alert(obj.status);            if(obj.status == 1){                $('p[name="data-list-p"]').append(obj.html);            }        }    });}

I am very sure that obj is actually in json format. However, alert is always undefined, which is very confusing!

Reply content:

The same ajax method requests different json data returned by php. it is strange that one can have a value without a value. The following shows how my ajax method processes the returned data.

function getUpList(_url, _u, _p){    $.ajax({        type:"GET",        data:$.param({uid:_u, page:_p}),        url:_url,        dataType:'json',        success:function(obj){            alert(obj.status);            if(obj.status == 1){                $('p[name="data-list-p"]').append(obj.html);            }        }    });}

I am very sure that obj is actually in json format. However, alert is always undefined, which is very confusing!

This is amazing. you are sure the two requests are both standard.jsonData! Standard should not appearundefined. You addevalTry it!

success:function(obj){    obj = eval("("+obj+")");    alert(obj.status);    if(obj.status == 1){        $('p[name="data-list-p"]').append(obj.html);    }}

Did you find the data in chrome console?

Is the format of data returned from two URLs incorrect! Check if json is not standard.

Should not returnJSONFormat,JSON string, Just click it.

Both chrome and firefox can see the returned parameters for good confirmation !~
Do not rush to output. status first, output the entire obj and then the result is better ~!

Change the json code returned by php to the same one.

Well. I'm sure you got it.jsonData, but thisobjDoes havestatusAttribute?

console.log(obj);It is convenient to use this method in the console.

var obj_json =  JSON.parse(obj);

String to 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.