2017-05-24 52 views
0

我試圖做一個AJAX投票刷新我的消息的div,但我有我的控制檯以下錯誤:阿賈克斯輪詢獲取URL數據返回找不到對象

http://localhost/~userb/grind/dashboard/[object%20Object] 404 (Not Found) 
send @ jquery.min.js:4 
ajax @ jquery.min.js:4 
n.(anonymous function) @ jquery.min.js:4 
update_chat @ convo.js:8 
jquery.min.js:4 GET 

這裏的片段JS的投票:

setInterval(update_chat, 2000); 

    function update_chat() 
    { 
     var enquiryId = parseInt($('#messageMain').data('id')); 

     $.get({url: '../includes/polling.php?id=' + enquiryId}) 
     .done(function(data) { 
      $('#messageMain').html(data); 
     }); 
    } 

的HTML:

<div class="panel panel-primary"> 
    <div class="panel-heading"> 
     <span class="glyphicon glyphicon-comment"></span> Chat 
    </div> 
    <div class="panel-body"> 
     <ul class="chat" id="messageMain" data-id="<?= $to_id ?>"> <!-- $to_id is what is used to get the messages --> 
      <!-- all messages are queried from database here --> 
     </ul> 
    </div> 
    <div class="panel-footer"> 
     <div class="input-group"> 
      <input id="btn-input" type="text" class="form-control input-sm" data-to="<?= $to_id ?>" placeholder="Type your message here..."> 
      <span class="input-group-btn"> 
       <button class="btn btn-warning btn-sm" id="btn-chat"> 
        Send</button> 
      </span> 
     </div> 
    </div> 
</div> 

Polling.php簡單地查詢數據庫,並返回HTMLŧ帽子在上面

+0

能否請您發表您的HTML?謝謝 ! – Christos

+0

@Christos添加了HTML。謝謝您的幫助 :) – nTuply

回答

1

變化$.get({url: '../includes/polling.php?id=' + enquiryId})的HTML用於$.get('../includes/polling.php?id=' + enquiryId)

的網址直接進入的。獲得的第一個參數()