Question

I have a function that uses .getJSON to get a JSON file from a server, get some data off it (a url is part of the data), and then call another function that needs to grab info from the parsed url (a plain Jane HTML page).

var jsonurl = "http://server.company.com/file.json"    
$.getJSON(jsonurl, function(data){
  //do some stuff, then call the below function

.

$.get("http://server.company.com/sub/dir/file.html", function(data){
    alert(data);  //this never fires
});

The JSON part is going through fine. The HTML part isn't doing anything. According to Firebug, it appears that the page is returned correctly (200), but I'm not getting any data.

The JSON file and the other plain HTML page are on the same server, just different directories, so I don't think it's a domain related issue. I initially tried getting the data using;

var req = new XMLHttpRequest();  
req.open("GET", "http://server.company.com/sub/dir/file.html", false);  
req.send(); 

But for some reason Firefox and Chrome both bark at the req.send(). My research lead me to think this was a (cross) domain related issue - the browser thinking that the page was requesting data outside of it's domain (all parties are on the same domain ending in "company.com").

Why is my $.get not working and/or how do I get rid of the XMLHttpRequest.send() error?

No correct solution

OTHER TIPS

Cross Domain ajax is only available with JSONP, used by the getJSON function.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top