Ok, so I understand what AJAX is. However, my problem is understanding what is required for it to run. For example, I have written three files that do a simple load a file when a button is pressed. Although this is not exactly AJAX with the whole XMLHTTP Request code (maybe I’m confused and this isn’t AJAX at all), it doesn’t work. My first question is what am I missing? Second, I read about how AJAX requires for the files to be in another server for it to work. Can anyone point to an article, tutorial, or even an explanation about this.
First File Code (This contains the button)
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body>
<input type="button" value="load" />
<div id="content"></div>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="ajax.js" >
</script>
</body>
</html>
Second file that contains the file that I want to load when the button is pressed.
<strong>This has been loaded into another page!</strong>
Third file contains the sudo-AJAX call.
$('#button').click(function () {
$('#content').load('test_ajax_return.php');
});
You are using id button for your click but it doesnt have the id “button”, give your button an id and change it in the click event handler.