Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Ajax and Firefox

 
Roman Mazur
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just out of curiosity, what happens if you use <div></div> instead of <div/>?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64613
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<div/> is not valid and will not work.
 
Roman Mazur
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"<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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What else would "<div/> is not valid and will not work" mean?! Did you even try it?
 
Roman Mazur
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I find that difficult to believe; can you access the div from the Firebug console?
 
Roman Mazur
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Pie
Posts: 1192
25
Android C++ Java Linux PHP Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I changed it but it didn't help.
This is the current code:
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...


if (window.xmlhttprequest) {

Seriously, why wouldn't you use a framework and skip all this manual, obviously error-prone stuff?
 
Karthik Shiraly
Bartender
Pie
Posts: 1192
25
Android C++ Java Linux PHP Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64613
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like JSONP? Since obviously there are a million map mashups?
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(With the caveat that the article is five years old and doesn't include recent developments, like JSONP.)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic