2011-01-21 3 views

답변

3

는 :

AJAX and Error: Invalid label

If you are using jQuery for example to do AJAX calls to the JSON webservice, you will probably be seeing the Javascript error Error: Invalid label To eliminate this error, tag jsoncallback=? onto the url when making the jQuery Ajax call to any JSON webservice eg

$.getJSON("http://www.geoplugin.net/json.gp?jsoncallback=?", 
function (data) { 
    for (var i in data) { 
     document.write('data["i"] = ' + i + '<br/>'); 
    } 
); 

그래서 나는 노력을 보여주고 있고 created a fiddle here (link) 덧붙였다.

0

문서는 :

Important: As of jQuery 1.4, if the JSON file contains a syntax error, the request will usually fail silently. Avoid frequent hand-editing of JSON data for this reason. JSON is a data-interchange format with syntax rules that are stricter than those of JavaScript's object literal notation. For example, all strings represented in JSON, whether they are properties or values, must be enclosed in double-quotes. For details on the JSON format, see http://json.org/ .

데이터가 올바른 JSON 형식으로 반환되고 있습니까? 의 다른 접근 시도하지 왜 :

$.ajax({ 
    url: url, 
    dataType: 'json', 
    data: data, 
    success: callback 
}); 

이 방법을 당신은 JSON 데이터 형식을 삭제하고 호출 데이터, JSON을 반환 여부를 작동하는지 확인 할 수있다.

브라우저 보안 제한으로 인해, 아약스 요청에는 동일한 출처 정책이 적용됩니다. 요청이 다른 도메인, 하위 도메인 또는 프로토콜에서 데이터를 성공적으로 검색 할 수 없습니다. this page (link)에 따르면