1

我一直在摆弄这个,绝对没有进展或运气。如果我取出 .ajax 它可以正常工作,但使用 .ajax 不会触发任何事件,甚至不会触发随机测试警报。你能看出我做错了什么吗?我试图遵循 Jquery 文档。PHP 工作。

<script type="text/javascript">
jQuery(document).ready(function ($) { // wait until the document is ready
$('div#chatroom').click(function(){
$.ajax({
    type: 'GET',
    url: 'chatget.php',
    data: { chatroomid: = '<?php echo $chatroomid; ?>'},
    datatype: 'html',
    cache: 'false',
    success: function(response) {
        $('#chatroom').append(response);
        alert('Load was performed.');
    },
    error: function(){
        alert('Fuuuuuuuuuuuuuu');
    }
}); // End Ajax  

alert('Fail');

}); // End onclick
});

</script>
4

3 回答 3

2

只是看着它..你有一个额外=的数据对象

data: { chatroomid: = '<?php echo $chatroomid; ?>'},
              ------^^--- here

应该

 data: { chatroomid: '<?php echo $chatroomid; ?>'},
于 2013-02-27T07:57:32.873 回答
1
<script type="text/javascript">
jQuery(document).ready(function ($) { // wait until the document is ready
$('div#chatroom').click(function(){
$.ajax({
    type: 'GET',
    url: 'chatget.php',
    data: { chatroomid: '<?php echo $chatroomid; ?>'},
    datatype: 'html',
    cache: 'false',
    success: function(response) {
        $('#chatroom').append(response);
        alert('Load was performed.');
    },
    error: function(){
        alert('Fuuuuuuuuuuuuuu');
    }
}); // End Ajax  

alert('Fail');

}); // End onclick
});

</script>

你能试试这个代码吗

于 2013-02-27T07:57:52.317 回答
1

在我看来错误在这里:一个额外的“=”

chatroomid: = '<?php echo $chatroomid; ?>'},

当出现这样的错误时,我通常使用jslint测试代码

于 2013-02-27T07:59:58.217 回答