JQuery Ajax不显示成功警报


JQuery Ajax Not Showing Success Alert

我正在尝试让JQuery Ajax工作,但没有获得成功警报。

代码如下:

<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>

…然后testing123.php文件:

<?php
    echo 'Hello there';
?>

我也添加了JQuery库。

当我点击按钮,我应该得到一个警告说"这工作",对吗?

我不明白为什么没有发生…

知道为什么吗?

括号使用不正确。纠正代码:

  $(document).ready(function() {    
            $('button').click(function() {    
                $.ajax({
                    url: 'testing123.php',
                    success: function(){
                      alert('this worked');
                    }
                });    
                return false;    
            });    
  });

您需要将哈希值与按钮id ('#button')放在一起。click

$(document).ready(function() {
$('#button').click(function() {
$.ajax({
url: 'testing123.php',
success: function(){
alert('test echo');
}
});
return false;
});
});