Why does jquery have different processing results when the same JSON string is input?

Source: Internet
Author: User
Why does the same JSON string input have different jquery processing results? function getOrderDishArea (){
$ ("# OrderDishList"). text ('');
// Var area;
// If (getItem ("areaName") = null ){
// Area = 'hefei ';
//} Else {
// Area = getItem ("areaName ")
//}
Document. getElementById ('Order _ dish_info_panel '). style. display = 'none ';
$. JsonP ({
Url: 'http: // shegoushop.com/app/ceshi.php? M = ClientApp & a = getArea & city_domain = hefei ',
Url: 'http: // public.6tie.com/index.php? M = ClientApp & a = getArea & city_domain = hefei ',

Success: function (data ){
Alert ("OK! ");
If (data ['MSG '] = "success" & data ['data']! = Null ){

$ ('# Order_dish_area_info_loading'). hide ();

Var orderDishStr = '';
Var jsondata = data ['data'];

For (var I = 0; I Var sum = I + 1;
/* OrderDishStr + = '';*/
OrderDishStr + ="

  • ";
    OrderDishStr + = "";
    OrderDishStr + = ''+ jsondata [I]. sortname + 'In business

';
}
$ ("# OrderDishList"). append (orderDishStr );
} Else {
Alert ("no data in the loading region! ");
}
}
});
}

As shown above, two different URLs are executed, and the same JSON string is returned, but the first URL is not executed, and the second URL can be executed.


Reply to discussion (solution)

Url: 'http: // shegoushop.com/app/ceshi.php? M = ClientApp & a = getArea & city_domain = hefei ',
Url: 'http: // public.6tie.com/index.php? M = ClientApp & a = getArea & city_domain = hefei ',
Success: function (data ){}
What is this usage?
The parameters of the jsonP ({}) method are in json format. Can a key name url be assigned twice in json format?

Url: 'http: // shegoushop.com/app/ceshi.php? M = ClientApp & a = getArea & city_domain = hefei ',
Url: 'http: // public.6tie.com/index.php? M = ClientApp & a = getArea & city_domain = hefei ',
Success: function (data ){}
What is this usage?
The parameters of the jsonP ({}) method are in json format. Can a key name url be assigned twice in json format?


The two URLs are tested. the Two URLs output the same JSON string after execution, but only one URL can be successfully executed. why? Comment out a URL during testing

The key name (url) is the same, and the latter overwrites the former. of course, only one

Sorry, I got it wrong,
Js. this is a cross-origin issue.
Ask the person who provides the interface to add cross-domain code on the server
Header ("Access-Control-Allow-Origin :*");

The domain name on your page is the same as the interface domain name to obtain data. if it is different, you need to add cross-domain code. I wrote this one, and there are a lot

The key name (url) is the same, and the latter overwrites the former. of course, only one



Maybe I have made an error. the execution is not two, but two, respectively. When one URL is executed, the other URL is commented out, but only one of the two URLs can be executed. This should be a cross-origin issue. I don't know how to handle it. Only one URL can be successfully executed, however, the two URLs throw the same json string.

It seems that this can only be used by the server, but it does not seem to be handled by js alone.
Add a header to the service end.

If it is not your own server, you have to create a file_get_content ();

Sorry, I got it wrong,
Js. this is a cross-origin issue.
Ask the person who provides the interface to add cross-domain code on the server
Header ("Access-Control-Allow-Origin :*");



After testing, the php Server adds the header ("Access-Control-Allow-Origin. Do not know the url: 'http: // public.6tie.com/index.php? M = ClientApp & a = getArea & city_domain = hefei ': Why can the test be executed? the same JSON file is thrown out in the PHP test. It should be a cross-origin issue, but this header declaration does not work.

Run the second URL:

Run the first URL:

 

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.