views:

361

answers:

3

Hi,

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.

+1  A: 

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"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
   <head>
      <title />
      <script type="text/javascript">
         function ws_results(obj) {
             alert(obj);
         }
      </script>
      <script type="text/javascript" src="http://someurl.com?foo=bar&amp;amp;callback=ws_results" />
   </head>
   <body />
</html>
antonj
thanks, I have actually found a solution to that one and forgot to write down the answer.
Tom
A: 

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!

Tom
A: 

It seems it Doesn't work only in Opera when you aren't in localhost.

carmichael84

related questions