jQuery的$。获得()函数成功与200,但返回在Firefox没有内容函数、内容、jQuery、Firefox

2023-09-10 14:46:42 作者:爱成碍

我写的jQuery我的第一位,而我在使用 jQuery.get一个问题()。我打电话这一点;

I'm writing my first bit of jQuery, and I'm having a problem with jQuery.get(). I'm calling this;

$.get(url, updateList);

在这里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>');
    }
}

函数运行,而 updateList 被调用。它工作正常在Internet&NBSP;浏览器。然而,在Firefox中,数据参数始终是空的。我希望它充满了我传递的URL的网页内容。我使用它错了?

The function runs, and updateList is called. It works fine in InternetExplorer. 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?

注;

在Firebug的,我已经启用的网络的面板,我也得到了展示的要求。我得到一个 200 OK 。该标题设置页看起来不错,而响应 HTML 面板都为空。 在我试图下载该网页是直的HTML页面 - 有一个与服务器code没有问题 在使用JavaScript的网页是本地的我的机器;我下载页面托管在互联网上。 在我试图从我的网页查看通过复制粘贴其网址到浏览器 - 它兴高采烈地返回内容 这排除了恶意加载项希望 - 在出现的错误,甚至在Firefox安全模式。 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.

推荐答案

您可能无法做到这一点,由于跨域安全。互联网&NBSP;从文件运行时,浏览器将让你的Ajax远程域:// ,但Firefox和Chrome不会

You probably won't be able to do this due to cross-domain security. InternetExplorer 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).