I’ve been trying to learn how to use jQuery AJAX with PHP.
My problem is that whenever I am selecting any other element besides document, nothing seems to work. What I want to is to simply prevent the page from loading after pressing the submit button to no avail.
I’ve tried using jQuery instead of $, and still no luck.
I am honestly not sure what I am doing, and I’ve tried searching for hours for the solution for this one.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script>
$("p").click(function() {
alert('test');
});
$("form").submit(function() {
alert('test');
return false;
});
</script>
<title>Insert title here</title>
</head>
<body>
<form action="process.php" method="post">
Inputs:<br />
<textarea rows="15" cols="60" id="input" name="input">Some text...
</textarea><br /><br />
Start:
<input type="text" id="start" name="start" />
End:
<input type="text" id="end" name="end" /><br />
<input type="submit" id="submit" name="submit" value="Submit">
</form>
<p id="output">Output: Some Random Text</p>
</body>
</html>
You are trying to select elements before they have loaded. Use the document ready event to run your code once the document has been loaded.