我有一個如下功能:如何使用post方法在jQuery ajax請求中使用timeout屬性?
function mark_unmark_user_answer(targ, answer, answer_id, test_id, test_type, question_no, module_url) {
if(checked==targ){
targ.checked=false;
checked=false;
} else {
checked=targ;
}
$.post(module_url, {'test_id':test_id, 'question_no':question_no, 'op':'mark_ans', 'test_type':test_type, 'answer_no':answer, 'answer_id':answer_id}, function(data) {
if(jQuery.trim(data)=='unmark_ans') {
$('input[type="radio"]').removeAttr('checked');
$('#display_'+question_no).removeClass('green');
$('#display_'+question_no).removeClass('blue');
$('#display_'+question_no).addClass('orange');
} else {
//$('#mark_review').val('Mark');
$('#display_'+question_no).removeClass('orange');
$('#display_'+question_no).removeClass('blue');
$('#display_'+question_no).addClass("green");
$('#mark_review').attr('disabled', false);
}
var total_questions = $('#total_questions').val();
test_question_attempted_count(total_questions);
});
}
我想超時30秒分配給此功能。因此,如果在30秒內未收到對Ajax請求的響應,則應該出現警告消息,指出「您的互聯網連接有問題」。否則,普通函數應該執行。
任何人都可以幫忙嗎?
在此先感謝。
請讓我知道,如果我的回答對你起作用,或者如果你對答案有任何問題。請接受我的答覆作爲正確的答案,如果它對您有用 - 以便其他用戶可以從中受益:知道答案有效並將問題標記爲已答覆。 – DhruvJoshi