1

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

2
  • What do you mean it gets stuck? Is the jQuery file in the same directory? Commented Mar 27, 2013 at 14:46
  • check your browser console to see if there was any errors Commented Mar 27, 2013 at 15:39

1 Answer 1

2

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); 
  }
});
Sign up to request clarification or add additional context in comments.

5 Comments

ok...I've checked the FF error console. it shows: "$ is not defined".
$ should stand for jQuery? jQuery is not defined?
try entering '$(document)' into the firefox console. it should return the document html if jQuery is working.
tnx. $(document) gives: "no element found"
not sure if this is thread is dead or not, but '$ is not defined' could mean you defined a jquery file before including the jquery package file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.