0

The following code isn't making any AJAX call (Nothing appears on Firebug's console)

<SCRIPT type="text/javascript" src="js/jquery-1.8.3.js"></SCRIPT> <script type="text/javascript"> $(document).ready(function() { alert( "hola" ); $.ajax({ url: "index.php?action=ajaxMenu&sa=get", dataType: "json", success: function(data, status, xhttp) { if ( data ) { alert ('Got Data'); } else { alert('No Data'); } } }) }) </script> 

The first alert gets executed.

However, if I manually enter into the url, I get the following response:

{"data":[{"id":"3","name":"Menu 1"},{"id":"4","name":"menu2"}]} 

Gotta be something simple, I think.

Thanks!!

4
  • Try using console.log instead of alerts. Firefox has some weird behavior concerning the latter Commented Jan 10, 2013 at 2:27
  • 3
    are both of your pages in the same folder? And are you opening the file through the file:/// scheme or using a server such as apache? Commented Jan 10, 2013 at 2:29
  • Does your network tab show the ajax request being fired? Commented Jan 10, 2013 at 2:29
  • 1
    @FabrícioMatté Yes, it was simple, I was accesing through file:///, thats why it wasn't getting executed. Thanks!! Put as answer. Commented Jan 10, 2013 at 2:30

1 Answer 1

5

Chrome won't allow you to execute XHR requests through the file:/// for security reasons. Use a local server such as WAMP, EasyPHP or XAMPP for testing =].

An workaround that is possible with Chrome is to start it from command line with this option:

--allow-file-access-from-files

But honestly, you'd end up running into other security restrictions sooner or later, hence using a local server is the way to go.

Sign up to request clarification or add additional context in comments.

2 Comments

I have firefox, seems that isn't allowed neither. Thanks!
Weird, it was allowed in FF a couple versions back. I guess they fixed that for security as well.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.