English 中文(简体)
is JsonP working with Opera, Chrome & 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.

最佳回答

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!

问题回答

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&amp;callback=ws_results" />
   </head>
   <body />
</html>




相关问题
jQuery redirect not working in non-IE browsers

I m trying to redirect all links to a particular page on our site to a secure connection using jQuery. This code works fine in IE, but it doesn t work in any other browser (tried it in Chrome, Firefox,...

Browser-friendly way to simulate anchor click with jQuery?

I m trying to simulate a click on an anchor tag using jQuery. I ve been digging around StackOverflow and Google for a while and haven t found anything that works on all of the browsers I m testing. So ...

Widescreen check on normal screen

I work normal screen and I develop some web application. When the application goes on widescreen some of the pages looks weired. Is there any way I can view my web page as it looks in Widescreen on my ...

Cross-browser development

I m developing a web application for a new service, starting from Firefox 3.5. The interface design is tableless, only using divs + CSS & performance-blessed practices. Now, while being ...

热门标签