jQuery $.get() function succeeds with 200 but returns no content in Firefox

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. The Headers tab looks fine, while the Response and HTML 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.

Answers:

Answer

You 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).

Answer

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.

Answer

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

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us Javascript

©2020 All rights reserved.