I'm writing my first bit of jQuery, and I'm having a problem with jQuery.get()
. I'm calling this;
$.get(url, updateList);
where updateList is defined like so;
function updateList(data)
{
if (data)
{
$('#contentlist').html(data);
}
else
{
$('#contentlist').html('<li><a href="#" id="synclink">Nothing found. Try again</a></li>');
}
}
The function runs, and updateList
is called. It works fine in Internet Explorer. However, in Firefox, the data
parameter is always empty. I would expect it to be filled with the content of the webpage I passed in as the URL. Am I using it wrong?
Notes;
- in Firebug, I've enabled the Net panel, and I get the request showing up. I get a
200 OK
. TheHeaders
tab looks fine, while theResponse
andHTML
panels are both empty. - The page I'm trying to download is a straight HTML page -- there's no problem with server code.
- The page with JavaScript is local to my machine; the page I'm downloading is hosted on the Internet.
- I've tried checking the URL by copy-pasting it from my page into the browser -- it happily returns content.
- The error occurs even in Firefox Safe Mode -- hopefully that rules out rogue addins.
I'm writing my first bit of jQuery, and I'm having a problem with jQuery.get()
. I'm calling this;
$.get(url, updateList);
where updateList is defined like so;
function updateList(data)
{
if (data)
{
$('#contentlist').html(data);
}
else
{
$('#contentlist').html('<li><a href="#" id="synclink">Nothing found. Try again</a></li>');
}
}
The function runs, and updateList
is called. It works fine in Internet Explorer. However, in Firefox, the data
parameter is always empty. I would expect it to be filled with the content of the webpage I passed in as the URL. Am I using it wrong?
Notes;
- in Firebug, I've enabled the Net panel, and I get the request showing up. I get a
200 OK
. TheHeaders
tab looks fine, while theResponse
andHTML
panels are both empty. - The page I'm trying to download is a straight HTML page -- there's no problem with server code.
- The page with JavaScript is local to my machine; the page I'm downloading is hosted on the Internet.
- I've tried checking the URL by copy-pasting it from my page into the browser -- it happily returns content.
- The error occurs even in Firefox Safe Mode -- hopefully that rules out rogue addins.
- 1 have you stepped through the server code to ensure that it returns any data? – Josh E Commented Jul 27, 2009 at 15:55
- 4 Completely unrelated, but I have to tell it: Yesterday, I was at a horse race for the first time in my life. I just had to bet on the horse called "Ajax". It came in fourth, so I lost my 2 Euros. Please continue, nothing to see here. – balpha ♦ Commented Jul 27, 2009 at 15:57
- Just noticed it works fine in IE. There is no code on the server -- it's a straight html page. – Steve Cooper Commented Jul 27, 2009 at 15:58
- have you tried copy-pasting the URL into a separate tab to ensure that the url variable is correct? – Josh E Commented Jul 27, 2009 at 16:00
- "have you tried copy-pasting the URL": I have - it works. – Steve Cooper Commented Jul 27, 2009 at 16:02
3 Answers
Reset to default 7You probably won't be able to do this due to cross-domain security. Internet Explorer will allow you to Ajax remote domain when running from file://
, but Firefox and Chrome won't.
Try to put both files on the same server and see if it works (it should).
You'll most likely need to fix your page that you're quering with XHR because it should be returning content. Copy paste the link in the Firebug net tab and make a new tab, and edit that page with your text editor so it spits content back.
Stick alert (or breakpoint in Firebug) and see if the data returned is not an object (or if there is any data). If the former - you may need to drill into the object to get your markup