File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes AJAX not working in Safari Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "AJAX not working in Safari" Watch "AJAX not working in Safari" New topic

AJAX not working in Safari

Mathias Nilsson
Ranch Hand

Joined: Aug 21, 2004
Posts: 367

I have got this simple script to work in
Firefox pc
Firefox mac
Opera PC
Chrome PC

but not in safari. It's driving me mad. Any pointers?

The onreadystatechange is not getting called in safari.

Devaka Cooray
ExamLab Creator

Joined: Jul 29, 2008
Posts: 3910

Try to instantiate the xml http object with "Msxml2.XMLHTTP" ActiveX object.

Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
Mathias Nilsson
Ranch Hand

Joined: Aug 21, 2004
Posts: 367
thanks but that didn't work!
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63837

Of course not. That's for IE.

Is the sever-side resource getting called? What other debugging steps have you taken?

And why aren't you using jQuery or Prototype or any of the other useful libraries to do Ajax for you? They take care of any browser differences.

[Asking smart questions] [About Bear] [Books by Bear]
Mathias Nilsson
Ranch Hand

Joined: Aug 21, 2004
Posts: 367
Actually, when using a plain servlet with the code I can get it to work in safari.

I have tried to set up this with wicket framework and it seams that safari can not find the resource but all other browsers can. So now I'm building a servlet
for upload instead. Need progressbar
Cloudgen C.F. Wong

Joined: Jul 15, 2009
Posts: 19
I've try the code you've posted. It works Okay with all the browsers. The problem seems to be some "Javascript" outside your code may go wrong. It may not due to the assignment of "url" to variable "u" without declaring "u" as local variable. But it may course problem if you use the variable "u" somewhere outside the block.

Mathias Nilsson
Ranch Hand

Joined: Aug 21, 2004
Posts: 367
This is a problem for safari and opera as well.

What I really trying to do is to make and multipart upload. and when the upload is started on the onsubmit I'm checking a ajax request. This is not the same way as posting with ajax because this will not work.
However, it seams that the responsiveness of the browsers stops. (in safari, opera. Not in IE ) So the only way is using an Iframe to get it to work with all browsers

I agree. Here's the link:
subject: AJAX not working in Safari
It's not a secret anymore!