简体   繁体   中英

Pulling json data from a web server into text

Hi all I've been stuck on this issue for a while. I am currently using dojo.xhrget to put the json data onto my html page as text. At the moment I keep getting the error on safari, it doesn't seem to respond to other browsers due to cross domain issues i believe -

" An unexpected error occurred: RequestError: Unable to load 171.51.21.41:3000/information.json status: 0"

I have attempted to use dojo.io.script, but it still comes up blank. I suspect for some reason it cannot read my json data - any help would be greatly appreciated.

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, "&nbsp;&nbsp;&nbsp;");

  targetNode.innerHTML = data;
},
error: function(error){
  targetNode.innerHTML = "An unexpected error occurred: " + error;
}
}

 // Call the asynchronous xhrGet
 var deferred = dojo.xhrGet(xhrArgs);
});

});

I borrowed this code & edited. I know the error statement comes up because of the error function; but I wish to know why & how I can access the json.

thanks in advance~

Snippet of my JSON:

[{"id":1,"Field":"Devices","Phase":"Final","Name":"MP3 Player"}]

你需要在你的xhrArgs网址中加入http://

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM