I am very new to jQuery, and I am probably doing this wrong, but here is my problem. I have a page where a user puts input into boxes and hits submit, where response data will be generated on the server and sent back with AJAX. However, nothing happens when I press submit… I know the function is being called, so I think my jQuery code is wrong.
Here is my code, simplified:
<html>
<head>
<style type="text/css">
#hide {
display:none;
}
</style>
<script type="text/javascript">
$(document).ready(function(){
$("#submit").click(doAjax());
});
function doAjax() {
$.ajax({
type:"GET",
data:"myquerystring",
url:"dummy.php"
}).done(function(data){
$("#hide").css("display","inline");
$("#result").html(data);
});
}
</script>
</head>
<body>
<p>Enter your text:</p>
<!--Code for textboxes-->
<button id="submit">Submit</button>
<p id="hide">Result:<pre id="result"></pre></p>
</body>
</html>
Right now, dummy.php is just:
<?php
echo "hi";
?>
so that’s not the problem. Can anyone help me with this?
UPDATE: Chrome tells me:
Uncaught TypeError: Object #<XMLHttpRequest> has no method 'done'
when i try to run doAjax()
It is working on my test. Make sure your jquery is version 1.5+ http://api.jquery.com/deferred.done/
Jquery 1.5