好吧所以我有一个调用RESTful网址的ajax脚本,这就是它返回给我的东西,一些像这样的json
{
"name": "camera-livingroom",
"address": 0,
"addressStr": "unknown",
"classID": 0,
"devProtocol": 999,
"displayInUI": true,
"displayLongState": "disconnected",
"displayRawState": "disconnected",
"folderID": 476125486,
"hasStateToDisplay": true,
"id": 1241016235,
"lastChanged": 479347270,
"lastChangedDateStr": "2015-03-11",
"lastChangedRFC3339": "2015-03-10T22:01:10Z",
"lastChangedRFC822": "Tue, 10 Mar 2015 22:01:10 GMT",
"lastChangedTimeStr": "12:01:10 AM",
"type": "Camera",
"typeFlags": 0,
"typeSupportsDim": false,
"typeSupportsEnergyMeter": false,
"typeSupportsHVAC": false,
"typeSupportsIO": false,
"typeSupportsOnOff": false,
"typeSupportsSensorValue": false,
"typeSupportsSpeedControl": false,
"typeSupportsSprinkler": false,
"versByte": 0,
"restParent": "devices"
}
这个JSON我无法控制,也无法改变,因为它来自程序中的api。
我用
调用JSON <script type="text/javascript">
function load(Test) {
$.ajax({
type: 'GET',
// TO DO
url: 'http://SERVERIP:8176/devices/camera-livingroom.json',
dataType: 'jsonp',
crossDomain: true,
success: function(data) {
alert(data);
}
});
}
</script>
<a class="editLink" onclick="load('Test');">test af link</a>
但这只是返回“SyntaxError:Unexpected token':'。Parse error。”
那么我做错了什么,我该怎么做才能解决它。
答案 0 :(得分:0)
您的代码对我来说很合适,所以我尝试使用$.getJSON
,同样的工作结果:
$.getJSON( "https://raw.githubusercontent.com/mozilla/contribute.json/master/schema.json?callback=?", function( data ){
console.log( data );
});