GeeCON Prague 2014*
The moose likes HTML, CSS and JavaScript and the fly likes Ajax and Firefox 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 and Firefox" Watch "Ajax and Firefox" New topic
Author

Ajax and Firefox

Roman Mazur
Ranch Hand

Joined: Sep 02, 2008
Posts: 42
Hi,
This is a html page with AJAX.
The code is working perfectly in Internet Explorer but is not working in Firefox.
The result is a simple JSON object. I also tried jQuery but the result was the same.
Does anybody know how to get the code working in FF?



Thanks,
Roman

SCJP 6, SCWCD J2EE 5 http://www.compcoding.com/
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Just out of curiosity, what happens if you use <div></div> instead of <div/>?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

<div/> is not valid and will not work.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Roman Mazur
Ranch Hand

Joined: Sep 02, 2008
Posts: 42
"<div/> is not valid and will not work. "

Are you saying that the code is not working in FF because of the div?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

What else would "<div/> is not valid and will not work" mean?! Did you even try it?
Roman Mazur
Ranch Hand

Joined: Sep 02, 2008
Posts: 42
I changed the div in the code but the result is the same (it is working in IE but not in FF)

Roman
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I find that difficult to believe; can you access the div from the Firebug console?
Roman Mazur
Ranch Hand

Joined: Sep 02, 2008
Posts: 42
Hi,
The div is not that important. You can display the result in different way like javascript alert().
I think the point is that the request object is null in FF.

Roman

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Well if you're not even making a *request* properly, sure, I guess it would have been good to include that info earlier.

I haven't done Ajax w/o a framework for years--no point, so I won't be able to help with your JavaScript code.
Karthik Shiraly
Ranch Hand

Joined: Apr 04, 2009
Posts: 513
    
    6
Roman Mazur wrote:
I think the point is that the request object is null in FF.


Note the case. It should be
request = new XMLHttpRequest();
Roman Mazur
Ranch Hand

Joined: Sep 02, 2008
Posts: 42
I changed it but it didn't help.
This is the current code:
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

...


if (window.xmlhttprequest) {

Seriously, why wouldn't you use a framework and skip all this manual, obviously error-prone stuff?
Karthik Shiraly
Ranch Hand

Joined: Apr 04, 2009
Posts: 513
    
    6
Roman Mazur wrote:I changed it but it didn't help.


Noticed the other mistake now, again in the case. Should be:
if (window.XMLHttpRequest)...

There is no entity named "xmlhttprequest" in window either - it'll always be false.

I too feel that if you're going to use ajax a lot, better to use one of the frameworks - jquery, dojo, etc.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

Karthik Shiraly wrote:I too feel that if you're going to use ajax a lot, better to use one of the frameworks - jquery, dojo, etc.

Seriously! All this code usually boils down to a single statement when using jQuery.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
That code should fail in any browser that has good security measures set.

JavaScript has a same origin policy. That means you can not call or interact with other domains. I am betting the error message you are getting is access denied.

You are trying to call a URL that is on a different domain with Ajax. That is not going to happen without a proxy. Most web services now support JSONP and some browsers support CORS.

Eric
Roman Mazur
Ranch Hand

Joined: Sep 02, 2008
Posts: 42
It looks like there is now way to run this code in FF.
I will look for different solution.

Thanks,
Roman
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Like JSONP? Since obviously there are a million map mashups?
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Roman Mazur wrote:It looks like there is now way to run this code in FF.
I will look for different solution.

Thanks,
Roman


You should not be able to do it in IE. Your settings allows sites to interact with other sites. That is not secure.

Eric
subhash kumar
Ranch Hand

Joined: Jul 14, 2010
Posts: 63
Hi,
you can read security issues related to the ajax making call to diiferent domains from following website link:
http://www.xml.com/lpt/a/1627


Subhash Kumar
Attitude is everything
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

(With the caveat that the article is five years old and doesn't include recent developments, like JSONP.)
 
GeeCON Prague 2014
 
subject: Ajax and Firefox