3
大家好,我一直在這個問題上停留了一段時間。我目前使用dojo.xhrget將json數據作爲文本放到我的html頁面上。在我不斷收到關於Safari瀏覽器錯誤的那一刻,它似乎並沒有對其他瀏覽器應對由於我相信跨域問題 -將json數據從web服務器拉到文本中
" An unexpected error occurred: RequestError: Unable to load 171.51.21.41:3000/information.json status: 0"
我試圖使用dojo.io.script,但它仍然空白。我懷疑由於某種原因,它不能讀取我的JSON數據 - 任何幫助將不勝感激。
require(["dojo"], function(dojo){
dojo.ready(function(){
// Look up the node we'll stick the text under.
var targetNode = dojo.byId("licenseContainer");
// The parameters to pass to xhrGet, the url, how to handle it, and the callbacks.
var xhrArgs = {
url: "171.51.21.41:3000/information.json ",
handleAs: "json",
load: function(data){
// Replace newlines with nice HTML tags.
data = data.replace(/\n/g, "<br>");
// Replace tabs with spaces.
data = data.replace(/\t/g, " ");
targetNode.innerHTML = data;
},
error: function(error){
targetNode.innerHTML = "An unexpected error occurred: " + error;
}
}
// Call the asynchronous xhrGet
var deferred = dojo.xhrGet(xhrArgs);
});
});
我借用此代碼&編輯。我知道錯誤聲明由於錯誤 函數而出現;但我想知道爲什麼&我如何訪問json。
在此先感謝〜
我的JSON的片段:
[{"id":1,"Field":"Devices","Phase":"Final","Name":"MP3 Player"}]
你試圖從比你不同的域獲取數據上? –
您的information.json是一個有效的json文件嗎? –
是的,這似乎是與其他種植者的問題,但Safari瀏覽器顯示錯誤的功能,我認爲這意味着它可以訪問它。 – Jose