OK so I'm a total n00b to everything, but I'm just trying to get jQuery to call my php script and get the return data. When I run this, it does not seem to try to access my php file but instead just appends "?wd=" to my url in the url bar, no "lookup.php" anywhere. The php script works fine when I call it directly. I've tried a bunch of stuff, and I just tried a fiddle with a working minimal example, then I editted it to use my url instead in to see if it would work and it broke the fiddle. So why does jQuery seem to hate my php file?
<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$("#input").on("submit", function()
{
var wd = $("#word").val();
$.ajax({
url: "lookup.php",
data: {word:wd},
success:function(result){
$("#return").html(result);
}
});
return false;
});
});
</script>
</head>
<body>
<form id="input" action="">
Word:<input type="text" name="word" autofocus /><br />
<input type="submit" value="Submit" />
</form>
<br />
<div id="return"><b>Return data here</b></div>
</body>
</html>
and my php:
<?php
$word = $_GET['wd'];
if ($word=="hi") {
echo "<p>Hey there!</p>";
} else {
echo "<p>Mi dispiace :-(</p>";
}
?>
I'm sure that it's something terribly obvious, so that you in advance for taking a few seconds to help me out.