Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$.get() works in IE but not FF

Tags:

jquery

Could someone please tell me what is wrong with this code? It works fine in IE8 but not in FF3.

$.get("http://google.com/", function(data) { alert(data); });

It shows me the alert window but it's empty.

like image 455
David Weng Avatar asked Aug 20 '10 16:08

David Weng


4 Answers

I believe it has to do with the cross domain AJAX restrictions between the two browsers. FireFox is more strict (secure) when it comes to AJAX. Your code violates FireFox's "Same Origin Policy"

Hope this helps!

like image 127
Aardvark Avatar answered Nov 11 '22 14:11

Aardvark


That code shouldn't work in Firefox or IE, due to the same origin policy. Chances are, you've set your security settings for the site's zone to be able to access data across domains:

To change this behaviour (and you probably should), go to Internet Settings -> Security -> Choose the zone for the current site -> Choose Custom level...

like image 42
Andy E Avatar answered Nov 11 '22 14:11

Andy E


Please read the documentation for $.get() (or really any other jQuery AJAX call).

http://api.jquery.com/jQuery.get/

It specifies the following lower down on the page: Due to browser security restrictions, most "Ajax" requests are subject to the same origin policy; the request can not successfully retrieve data from a different domain, subdomain, or protocol.

This is likely the source of your problem.

like image 38
Ender Avatar answered Nov 11 '22 14:11

Ender


You cannot use AJAX to send a request to a different domain.

In IE, you apparently enabled this option.

This is a bad security hole.

You should re-disable it immediately

Go to Internet Options, Security, Custom Level, Miscellaneous, and disable Access Data Sources across Domains.

like image 2
SLaks Avatar answered Nov 11 '22 14:11

SLaks