JsonP 是否可以与 Opera、Chrome 和 Chrome 一起使用?野生动物园?

发布于 2024-08-13 18:58:34 字数 717 浏览 1 评论 0原文

在我正在建立的网站上, 当您登录时(因为数据库位于其他服务器上), 我使用 json padding 来检查用户是否具有正确的凭据。

它工作完美(ie7、ie8 和 FF),直到我在 chrome、safari 和 FF 上尝试它。歌剧完全是一场灾难。

    $.ajax({
  type: "GET",
  dataType: "jsonp",
  url: "http://someurl.com",
  data: aRequestData,
  cache: false,
  error: function (XMLHttpRequest, textStatus, errorThrown) {
    // typically only one of textStatus or errorThrown
    // will have info
    alert("Error occured textStatus=" + textStatus + " errorThrown=" + errorThrown);
  },
  success: function(data) {
    alert('success');    
  }
});

简单明了,它可以在浏览器窗口中工作,然而,令我大惊讶的是,它在 chrome、safari 和 Safari 中不起作用。歌剧,从未达到成功警报。

有谁知道如何解决这个问题?

谢谢。

On a web site that I am building ,
when you log in (because the database is on an other server),
I use json padding to check if the user as the right credentials.

It's working flawlessly (ie7,ie8 & FF), until I tried it on chrome, safari & opera where it's a complete disaster.

    $.ajax({
  type: "GET",
  dataType: "jsonp",
  url: "http://someurl.com",
  data: aRequestData,
  cache: false,
  error: function (XMLHttpRequest, textStatus, errorThrown) {
    // typically only one of textStatus or errorThrown
    // will have info
    alert("Error occured textStatus=" + textStatus + " errorThrown=" + errorThrown);
  },
  success: function(data) {
    alert('success');    
  }
});

Plain and simple and it works in browser window, however, to my big surprise it did not work in chrome, safari & opera, never got to the success alert.

Does anyone know how to solve this issue?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

暖阳 2024-08-20 18:58:34

您是否尝试过使用 Safari 和 Chrome 的内置开发人员工具来检查您的请求是否收到 HTTP 状态代码 200 的响应?

在 Chrome 中,您可以从“查看”菜单访问这些工具,选择“资源”选项卡以查看发出的所有请求。我认为您在使用 Safari 时需要在某些设置中激活这些工具。
alt text

如果您没有获得状态 200,您也可以尝试创建不带 jQuery 的版本以排除那里发生的错误从你的电话来看,我认为 jQuery 将在不调用任何错误函数的情况下失败,将 JSONP 与 jQuery 一起使用的文档在错误处理方面不是很简洁。

使用以下内容的编辑版本创建一个 html 文件并将其加载到浏览器中:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
   <head>
      <title />
      <script type="text/javascript">
         function ws_results(obj) {
             alert(obj);
         }
      </script>
      <script type="text/javascript" src="http://someurl.com?foo=bar&callback=ws_results" />
   </head>
   <body />
</html>

Have you tried using the built in developer tools for Safari and Chrome to check if you get a response with HTTP status code 200 from your request?

In Chrome you can access these tools from the 'View' menu, choose the 'Resources' tab to see all requests made. I think you'll need to activate these tools in some setting when using Safari.
alt text

You could also try to create version without jQuery to rule out errors made there, if you don't get status 200 from your calls I think jQuery will fail without calling any error functions, the documentation for using JSONP with jQuery is not very concise regarding error handling.

Create a html file with an edited version of the following content and load it in your browsers:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
   <head>
      <title />
      <script type="text/javascript">
         function ws_results(obj) {
             alert(obj);
         }
      </script>
      <script type="text/javascript" src="http://someurl.com?foo=bar&callback=ws_results" />
   </head>
   <body />
</html>
少年亿悲伤 2024-08-20 18:58:34

问题出在 html 页面标题上,在进行 ajax 调用的“Thickbox”(jQuery Thickbox 插件)中!

在这种情况下,Firefox 或 IE 不介意重复的标头,但 WebKit 引擎却介意!

我只需删除多余的标头,一切就回到正轨。

谢谢大家!

The problem was left over html page header, in a "Thickbox" (jQuery Thickbox plugin) where the ajax call was made!

Firefox or IE don't mind repeated headers in that case, but the WebKit engine does!

I just had to remove the extra headers, and everything was back on tracks.

Thanks everyone!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文