2013-02-27 77 views
1

我已經擺弄這個,絕對沒有進展或運氣。如果我拿出.ajax,它可以正常工作,但是.ajax什麼都不會觸發,甚至沒有隨機測試警報。你能看到我做錯了嗎?我試圖遵循Jquery文檔。 PHP的作品。Jquery,Onclick和Ajax

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

更改錯誤時'chatroomid:=「''to'chatroomid:'<?php echo $ chatroomid; ?>''所以減去'=' – 2013-02-27 07:57:21

回答

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> 

ü可以試試這個代碼

+0

這是等號是XD的問題; – Rujikin 2013-02-27 08:01:12

2

只是尋找熱塑成型吧..你有一個額外的=數據對象

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

應該

data: { chatroomid: '<?php echo $chatroomid; ?>'}, 
+1

哦,哈哈哈!正在寫PHP。是的,修好了,謝謝! – Rujikin 2013-02-27 08:00:33

+0

welocme ....快樂編碼 – bipen 2013-02-27 08:01:28

1

錯誤在我看來:額外的「=」

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

我通常測試與jslint代碼有這樣一個