<html>
<head>
<title>Testing AJAX</title>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
function init() {
$("#form1").submit(submitForm);
}
function submitForm() {
var paramValue = $("#param_input").val();
$.ajax({
type: "GET",
url: 'http//xxx.edu/xxx/autocomplete.php',
data: {
query: paramValue
},
dataType: "json",
complete: function(data){
alert(JSON.stringify(data));
}
});
}
// On page load
$(document).ready(init);
</script>
</head>
<body>
<form id="form1" name="form1_name" action="" >
<label for="find">Value</label>
<input type="text" name="param" id="param_input" />
<input type="submit" name="button" id="button" value="Find">
</form>
</body>
</html>
I really want to be able to query my PHP script (which returns a JSON via json_encode()) and use that JSON information.
Right now the alert box says this:
{"readyState":0,"responseText":"","status":0,"statusText":"error"}
So I'm doing something wrong. Any ideas? I'm all new to AJAX / jQuery.
EDIT: added dataType: "json" but that did not help - still returning wrong JSON stuff...