Probably the simplest usage of $.ajax and $.get and yet it fails.
I’m pulling in HTML from a URL on the same domain:
$.get("/url", function(data) {
console.log(data);
});
The problem here is that the function returns empty, without an error, without a “cross-domain” alert. But if I check the network logs, the request was completed successfully and a full string of HTML was returned.
So what could possibly junk jQuery? Does it jam if the response had a format it didn’t like?
I’m not exactly sure why it made the difference, but using this:
Got it working. Must be related to how jQuery handles the data.
Update
I can confirm the cause of the problem. There was a rogue header injected into the response, so the content-type was coming back as
application/jsonalthough it was regular text. So most likely jQuery was trying to parse JSON that was actually HTML or just ignoring it altogether.Lesson learned: check your response headers.