[英]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()
. 我正在写我的jQuery的第一部分,而
jQuery.get()
遇到了问题。 I'm calling this; 我叫这个
$.get(url, updateList);
where updateList is defined like so; 像这样定义updateList;
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. 该函数运行,并调用
updateList
。 It works fine in Internet Explorer. 在Internet Explorer中可以正常工作。 However, in Firefox, the
data
parameter is always empty. 但是,在Firefox中,
data
参数始终为空。 I would expect it to be filled with the content of the webpage I passed in as the URL. 我希望它会填充我作为URL传入的网页的内容。 Am I using it wrong?
我使用错了吗?
Notes; 笔记;
200 OK
. 200 OK
。 The Headers
tab looks fine, while the Response
and HTML
panels are both empty. Headers
选项卡看起来很好,而“ Response
和“ HTML
面板都为空。 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. 从
file://
运行时,Internet Explorer允许您访问Ajax远程域,但Firefox和Chrome不允许。
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. 您很可能需要使用XHR修复您要查询的页面,因为它应该返回内容。 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.
复制链接,将链接粘贴到Firebug的“网络”标签中,然后新建一个标签,然后使用文本编辑器编辑该页面,使其返回内容。
Stick alert (or breakpoint in Firebug) and see if the data returned is not an object (or if there is any data). 保持警报(或Firebug中的断点),并查看返回的数据是否不是对象(或是否有任何数据)。 If the former - you may need to drill into the object to get your markup
如果是前者-您可能需要深入研究对象以获取标记
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.