當檢索JSON對象,我收到以下錯誤:語法錯誤:無效的標籤,同時檢索JSON對象
- 語法錯誤:在Mozilla無效的標籤。
- 未捕獲的SyntaxError:意外的標記:在Chrome
我的JSON對象是以下格式:
{
"userName" : "clevermeal835",
"userRole" : "Participant",
"userAccountStatus" : "Active"
}
代碼:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script src="Scripts/jquery-min.js"></script>
<script src="Scripts/jquery_validate.js"></script>
<script>
$(document).ready(function() {
loadLatestTweet();
});
function loadLatestTweet(){
var xhr = new XMLHttpRequest();
var uid = "clevermeal835";
var pwd = "Welcome_1";
var userType = "participant";
var surl = 'http://localhost:8080/RESTlet_WS/MobiSignIn/{"userName":"'+uid+'","password":"'+pwd+ '","userType":"'+userType+'"}&callback=?';
var jqxhr = $.getJSON(surl, function() {
alert("success");
}).success(function() { alert("second success"); }).error(function() { alert("error"); }).complete(function() { alert("complete"); });
jqxhr.complete(function(){ alert("second complete"); });
}
</script>
</head>
<body>
<input id="jsonpbtn2" type="submit" value="button" />
</body>
</html>
你告訴了jQuery期待JSONP,但響應看起來像JSON,而不是JSONP。響應評估爲JavaScript,但由於JSON不是有效的JavaScript,因此會出現該錯誤。你必須設置你的服務器來返回JSONP。 – 2012-08-09 11:31:52
[JSON請求無效標籤錯誤]的可能的重複(http://stackoverflow.com/questions/2816653/invalid-label-error-with-json-request) – 2012-08-09 11:32:13
可以請你澄清你的意思是通過設置服務器返回jsonp。其實我已經嘗試了json,jsonp。 – paripurna 2012-08-09 11:37:11