简体   繁体   English

jQuery $ .get()函数以200成功但在Firefox中不返回任何内容

[英]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; 笔记;

  • in Firebug, I've enabled the Net panel, and I get the request showing up. 在Firebug中,我启用了“ 网络”面板,并显示了请求。 I get a 200 OK . 我得到200 OK The Headers tab looks fine, while the Response and HTML panels are both empty. Headers选项卡看起来很好,而“ Response和“ HTML面板都为空。
  • The page I'm trying to download is a straight HTML page -- there's no problem with server code. 我要下载的页面是纯HTML页面-服务器代码没有问题。
  • The page with JavaScript is local to my machine; 带有JavaScript的页面在我的机器上是本地的; the page I'm downloading is hosted on the Internet. 我正在下载的页面托管在Internet上。
  • I've tried checking the URL by copy-pasting it from my page into the browser -- it happily returns content. 我尝试通过将URL从页面复制粘贴到浏览器中来检查URL,它很高兴返回内容。
  • The error occurs even in Firefox Safe Mode -- hopefully that rules out rogue addins. 即使在Firefox安全模式下也会发生错误-希望可以排除流氓插件。

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.

相关问题 recpatcha返回200,但仍然与jQuery ajax错误 - recpatcha returns 200, still get error with jQuery ajax 追加内容时,jQuery返回“未定义不是函数” - jQuery returns 'undefined is not a function' when appending content HTTP请求返回200 OK,但没有响应内容 - HTTP Request returns 200 OK but no content in response JQuery的Ajax函数在chrome中运行但在firefox中返回404 - JQuery's Ajax function works in chrome but returns 404 in firefox jQuery $ .ajax使用JSONP调用跨域,返回状态200,但是错误函数被调用而不是成功 - jQuery $.ajax call for cross domain with JSONP, returns status 200, but error function is being called instead of success jQuery $ .get()不起作用,返回状态200,无错误,但客户端无响应 - jQuery $.get() not working, returns status 200 without errors, yet no response on client side 文档元素之后的垃圾Firefox错误使用JQuery Get加载内容 - junk after document element Firefox Error Loading Content With JQuery Get jQuery控件的AJAX文本属性成功,返回[object Object] - AJAX text property of jQuery control succeeds, returns [object Object] async function 不执行返回200 - Async function returns 200 without executing 如何确定函数中的AJAX调用返回错误还是成功? - How to figure out whether an AJAX call in a function returns an error or succeeds?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM