Reputation: 49422
I am trying to get JQuery Ajax to work but not getting a success alert.
Here is the code:
<script type="text/javascript">
$(document).ready(function(
$('button').click(function() {
$.ajax({
url: 'testing123.php',
success: function(){
alert('this worked');
}
});
return false;
});
));
</script>
<button>Click Here</button>
...then the testing123.php file:
<?php
echo 'Hello there';
?>
I DO have JQuery library added too.
When I click the button I should be getting an alert saying "this worked" right?
I don't understand why it's not happening...
Any ideas why?
Upvotes: 0
Views: 6465
Reputation: 628
you need to put hash along with button id ('#button').click
$(document).ready(function() {
$('#button').click(function() {
$.ajax({
url: 'testing123.php',
success: function(){
alert('test echo');
}
});
return false;
});
});
Upvotes: 0
Reputation: 4185
Incorrect use of parantheses. Corrected code:
$(document).ready(function() {
$('button').click(function() {
$.ajax({
url: 'testing123.php',
success: function(){
alert('this worked');
}
});
return false;
});
});
Upvotes: 2