2016-11-17 80 views
0

我想與ajax編碼聊天框,但是當我撥打電話時,php文件shatbox.php不會出現。這裏是代碼和GitHubDiff。Ajax驗證發佈錯誤html

GitHubb Diff

$(document).ready(function(){ 
 
\t $('#submit').on('click',function(){ 
 
\t \t var name = $('#name').val(); 
 
\t \t var shout = $('#shout').val(); 
 
\t \t var date = getDate(); 
 
\t \t var dataString = 'name=' + name + '&shout=' + shout + '&date' + date; 
 

 
\t \t // validation 
 
\t \t if(name == '' || shout == ''){ 
 
\t \t \t alert('please fill Your name and shout'); 
 
\t \t }else{ 
 
\t \t \t $.ajax({ 
 
\t \t \t \t type:"POST", 
 
\t \t \t \t url:"../jschat/shoutbox.php", 
 
\t \t \t \t data: dataString, 
 
\t \t \t \t cache: false, 
 
\t \t \t \t success: function(html){ 
 
\t \t \t \t $('#shout ul').prepend(html); 
 
\t \t \t \t } 
 
\t \t \t }); 
 
\t \t } 
 

 
\t \t return false ; 
 
\t }); 
 
}); 
 
function getDate(){ 
 
\t var date; 
 
\t date = new date; 
 
\t date = date.getUTCFullYear() +'-'+ 
 
\t \t ('00' + (date.getUTCMonth() +1)).slice(-2)+'-'+ 
 
\t \t ('00' + date.getUTCDate().slice(-2)+' '+ 
 
\t \t ('00' + date.getUTCHours().slice(-2)+ ':'+ 
 
\t \t ('00' + date.getUTCMinutes().slice(-2)+':'+ 
 
\t \t ('00' + date.getUTCSeconds().slice(-2); 
 
\t return date; 
 
}

+0

開發控制檯中的任何錯誤? –

回答

1

中有功能getDate 2個錯誤:

1. Date對象區分大小寫

2.有一些缺少右括號從date.getUTCMonth

function getDate() { 
    var date = new Date; 
    date = date.getUTCFullYear() + '-' + 
     ('00' + (date.getUTCMonth() + 1)).slice(-2) + '-' + 
     ('00' + date.getUTCDate()).slice(-2) + ' ' + 
     ('00' + date.getUTCHours()).slice(-2) + ':' + 
     ('00' + date.getUTCMinutes()).slice(-2) + ':' + 
     ('00' + date.getUTCSeconds()).slice(-2); 
    return date; 
} 

開始,這可能是原因你的問題。

+0

謝謝你解決問題解決 –

+0

很高興。如果可能,請將答案標記爲已接受。 –

+0

完成^^謝謝你的幫助 –

0

文件的位置似乎是問題

url:"../jschat/shoutbox.php", 

試試這個

url:"../shoutbox.php", 
+0

其工作正常 url:「../ jschat/shoutbox.php」, –