English 中文(简体)
json UncattynexError: Unexpected token.
原标题:json Uncaught SyntaxError: Unexpected token :

JSON案。

$(document).ready(function() {

    jQuery.ajax({ 
        type:  GET ,
        url:  http://wncrunners.com/admin/colors.json  ,
        dataType:  jsonp , 
        success: function(data) { 
            alert( success );
        }
    });


  });//end document.ready

RAW要求:

GET http://wncrunners.com/admin/colors.json?callback=jQuery16406345664265099913_1319854793396&_=1319854793399 HTTP/1.1
Host: wncrunners.com
Connection: keep-alive
Cache-Control: max-age=0
User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.106 Safari/535.2
Accept: */*
Referer: http://localhost:8888/jquery/Test.html
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

The RAW Response:

HTTP/1.1 200 OK
Date: Sat, 29 Oct 2011 02:21:24 GMT
Server: Apache/1.3.33 (Unix) mod_ssl/2.8.22 OpenSSL/0.9.7d SE/0.5.3
Last-Modified: Fri, 28 Oct 2011 17:48:47 GMT
ETag: "166a2402-10-4eaaeaff"
Accept-Ranges: bytes
Content-Length: 16
Content-Type: text/plain
Connection: close

{"red" : "#f00"}

JSON正在回复中(红点:#f00),但 Chrome报告。 UncaultyntaxError: Unexpected token :nuts.json:1

If I navigate directly to url itself, the JSON is returned and is displayed in the browser.

如果我主宰肤色的内容。 json into JSLINT, the json accreditations.

有什么想法,我为什么会发现这一错误,我从来不会给成功带来挫折?

EDIT - 上文提到的j Query.ajax()电话在jsfiddle.net运行良好,并按预期恢复警戒。

EDIT 2 - this URL works fine http://api.wunderground.com/api/8ac447ee36aa2505/geolookup/conditions/q/IA/Cedar_Rapids.json I noticed that it returned as TYPE: text/javascript and Chrome did not throw the Unexpected Token. I ve tested several other url s and the ONLY one that does not throw the Unexptected Token is the wunderground that is returned as TYPE: text/javascript.

Streams returned as text/plain and application/json are not being parsed correctly.

最佳回答

http://en.wikipedia.org/wiki/JSONP“rel=“noretinger”>JSONP response,这就是为什么j Query 增加了 回顾=j Query164063456265099913_1319854793396&_=1319854793399。 其中一部分是URL(你可以在你放弃请求时看到这一点)。

你回来的是JSON,而不是JSONP。 你的回答是

{"red" : "#f00"}

and expect

jQuery16406345664265099913_1319854793396({"red" : "#f00"})

如果你实际上需要利用JSONP来掌握同样的原产地政策,那么担任<代码>colors.json的服务器实际上需要能够回复JSONP的回复。

If the same origin policy isn t an issue for your application, then you just need to fix the dataType in your jQuery.ajax call to be json instead of jsonp.

问题回答

在过去几天里,我一直试图亲眼看到这一点。 使用旧的json数据Type给你带来了交叉来源问题,同时将数据Type用于jsonp,使上述数据“无法阅读”。 因此,显然有两种办法,第一个避开了我,但似乎是一种潜在的解决办法,我可能会做一些错误。 本文[]。

The one that worked for me is as follows: 1- download the ajax cross origin plug in [ http://www.ajax-cross-origin.com/ ]. 2- add a script link to it just below the normal jQuery link. 3- add the line "crossOrigin: true," to your ajax function.

善待! 我的《工作守则》是:

  $.ajax({
      crossOrigin: true,
      url : "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.86,151.195&radius=5000&type=ATM&keyword=ATM&key=MyKey",
      type : "GET",
      success:function(data){
         console.log(data);
      }
    })

我也存在同样的问题,解决办法是把 j子放在这一职能中。

jsonp

......

iii

可能需要在引言中加以总结,并使之成为扼杀。 Java本可能不喜欢其特质。





相关问题
ajax login using httpRequest?

I am trying to develop my login script to give feedback to the user if the login is valid or not. Basically if it isn t correct a div box will show saying its wrong, if its correct it will show its ...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

How can i update div continuously

I have asp.net application where i have a div which showing the value from other site. The value of that site is changing continuously. I want that my div will automatically update in some interval ...

热门标签