连接ajax和php不起作用

连接ajax和php不起作用,php,jquery,ajax,Php,Jquery,Ajax,这个代码有什么问题? 它是通过ajax更改菜单和页面,而不刷新页面,但它不起作用 这是我的ajax代码 <script> $(document).ready(function() { $('.news').click(function give(id){ $('#main-unit').text('Please Wait...'); var place= id;

这个代码有什么问题? 它是通过ajax更改菜单和页面,而不刷新页面,但它不起作用 这是我的ajax代码

<script>
        $(document).ready(function() {
            $('.news').click(function give(id){
                $('#main-unit').text('Please Wait...');
                    var place= id;
                    $.ajax({
                        url:'pages/news.php',
                        type:'POST',
                        data:'where='+place,
                        statusCode:{
                            success: function(data){
                                $('#main-unit').html(data);
                            }
                        }
                    });
            });
        });
    </script>
这是我的html标签

<ul>
   <li><a class="news" onclick=\"give('news')\" href="#">news</a></li>
</ul>
和php代码

mysql_connect("localhost", "root", "")
    or die(mysql_error()); 
    mysql_select_db("basi")
    or die(mysql_error()); 
    if($_POST['where']=='news'){
        $result = mysql_query("SELECT * FROM contents WHERE type = 0");
        while ($row = mysql_fetch_array($result)){
            $title = $row['title'];
            $text = $row['text'];
            echo"
            <div class='title'><span>$title</span></div>
            <div class='content'>
            $text
            </div>
            ";
        }
    }
从数据库中读取的信息不会返回html文件。

FTFY

<script>
        $(document).ready(function() {
            $('.news').click(function give(id){
                $('#main-unit').text('Please Wait...');
                    var place= id;
                    $.ajax({
                        url:'pages/news.php',
                        type:'POST',
                        data:'where='+place,
                        //I believe your mistake was here
                        success: function(data){
                                $('#main-unit').html(data);
                         }
                    });
            });
        });
    </script>

问题在于JavaScript。您正在等待文档准备就绪,并且错误地绑定了未使用的单击事件侦听器!尝试:

<a class="news" onclick="give('news')" href="#">news</a>

控制台上怎么说?没什么,只显示请稍候。。。[$'main-unit'。文本'Please Wait…';]然后不显示任何内容我指的是调试控制台,即按浏览器上的F12键获得的控制台。
<script>
    function give(id) {
        $('#main-unit').text('Please Wait...');
        var place = id;
        $.ajax({
            url:'pages/news.php',
            type:'POST',
            data:'where='+place,
            statusCode:{
                success: function(data){
                    $('#main-unit').html(data);
                }
            }
        });
    }
</script>
$(document).ready(function() {
    $('.news').click(function(e) {
        give('news');
    });
});