我想實現一個簡單的AJAX GET請求。該請求告訴服務器刪除數據庫中的文檔。雖然我從服務器獲得文檔被刪除的確認信息,但Chrome Inspector顯示請求處於「掛起」狀態,最終導致服務器錯誤。簡單的AJAX獲取請求是「正在等待」
我在做什麼不正確?
HTML
<div class="delete-note">
<a href="#"><i class="icon-minus-sign"></i></a>
</div>
JS
$('.delete-note').click(function(e) {
var url = '/docs/' + doc_id + '/note_destroy/' + note_id;
$.ajax({
type: "GET",
url: url,
cache: false,
});
e.preventDefault();
});
編輯:包括服務器端代碼:
節點/快遞
exports.note_destroy = function(req, res) {
Doc.findOne({ doc_id : req.params.doc_id }, function(err, data) {
if (err) throw (err);
note_id = req.params.note_id;
data.notes.id(note_id).remove();
data.save(function(err) {
if (err) throw (err);
console.log('note ' + note_id + 'is removed.');
});
});
};
這是挑剔的,但如果請求是要刪除的東西,POST或DELETE請求會比GET更合適。 – gbtimmon 2013-04-29 17:51:42
我猜這個問題是服務器端,請求沒有關閉,所有? – adeneo 2013-04-29 17:52:14
什麼/您在哪裏看到服務器確認? – 2013-04-29 17:53:24