mzzxx11
mzzxx11

Reputation: 15

jquery $.get() not working on localhost

I'm trying to use jquery $.get() to obtain values from a server file. Both files are currently on my machine in the /var/www directory (using linux).

I am aware of the cross-domain restriction for ajax, hence I placed the two files in /var/www.

The "client" file (f1.htm) is:

<!DOCTYPE html>
<html>

<head>
<script src="jquery-1.9.1.min.js"></script>
</head> 

<body>

<script type="text/javascript">
    $.get( "f11.htm", function( data, status ){ alert( "1" ); } );
/*
    xmlhttp=new XMLHttpRequest();
    xmlhttp.open("GET","f11.htm",false);
    xmlhttp.send();
    alert( xmlhttp.readyState + " " + xmlhttp.status );
*/
    alert( "2" );
</script>

</body>

</html>

while the "server" script (f11.htm) is simply:

<html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<head>
</head> 

<body>

<?php
echo "server text";
?> 

</body>

</html>

the client script ("f1.htm") gets stuck at the $.get() line. I've tried this with xmlhttprequest (which is commented), and it works. why is the $.get() line not working?.

TIA

Upvotes: 1

Views: 8281

Answers (1)

Garrett
Garrett

Reputation: 1688

You can try this code to examine the error function being returned instead of the shorthand $.get.

$.ajax({
  type:'GET',
  url: 'f11.htm',
  data: {},
  success: function(data) {
   console.log(data); 
  }, error: function(jqXHR, textStatus, errorThrown) {
   console.log(errorThrown); 
  }
});

Upvotes: 2

Related Questions