0

I am very new to using jQuery so please bear with me. I am using a line of code found online. The code works when uploaded to my gatorhost server, bit not when testing on my local computer.

Both the index.html file and the ajax.html (the file being loaded) are in the same folder both on my hard drive and on my host server. I get "0 error"

<div id="success"></div>
<b>Error Response:</b>
<div id="error"></div>
<script>
$( "#success" ).load( "ajax.html #newimage", function( response, status, xhr ) {
if ( status == "error" ) {
var msg = "Sorry but there was an error: ";
$( "#error" ).html( msg + xhr.status + " " + xhr.statusText );
}
});
</script>
Curtis
  • 9
  • 1
  • How are you including jQuery? Does the referenced file actually exist on your local computer? What is your console saying? – Jonast92 Sep 29 '15 at 23:46
  • I don't think you can use ajax on local files if you are doing that. Browsers will generally load local files if you type them in the url, but an XmlHttpRequest requires an actual http connection to a server. Check your console for errors and the network tab in your browser. For a simple server, install node and do 'npm install http-server' then run 'http-server' [SO Question - second answer](http://stackoverflow.com/questions/6084360/using-node-js-as-a-simple-web-server) – Jason Goemaat Sep 29 '15 at 23:47
  • try doing "/ajax.html #newimage" with the slash at the beginning, see if that works – Titus Popovici Sep 29 '15 at 23:53

0 Answers0