bfunc({
"query": {
"count": 1,
"created": "2013-05-03T06:20:01Z",
"lang": "en-US",
"diagnostics": {
"publiclyCallable": "true",
"cache": {
"execution-start-time": "32",
"execution-stop-time": "32",
"execution-time": "0",
"method": "GET",
"type": "MEMCACHED",
"content": "http://www.vtualerts.com/robots.txt"
});
這是我需要使用javascript和jQuery解析的JSON數據。我試圖做這樣的......使用Javascript和jQuery解析JSON
<div id="placeholder"></div>
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script>
$.getJSON('myjson.json', function(data) {
var output= data.cbfunc.query.count+ "" + data.cbfunc.query.created;
document.getElementById("placeholder").innerHTML=output;
});
但我得到一個錯誤
的XMLHttpRequest無法加載文件:///home/shivratna/Desktop/myjson.json。 Access-Control-Allow-Origin不允許Origin null。
請大家幫忙。
真誠的感謝
URL正確嗎? – 2013-05-03 07:04:44
嘗試放置警報(「data:」+ JSON.stringify(data));也許你正在獲取數據。通過放置這條線進行驗證。 – Anil 2013-05-03 07:05:08
'bfunc(...)'不是有效的JSON。這甚至不是有效的JSONP。 – 2013-05-03 07:05:50