[英]Jquery ajax call within the success function of another ajax call not working and not telling the type of error correctly
[英]call function within ajax success
我正在嘗試從AJAX成功處理程序中調用函數,但該函數被忽略
$.ajax({
url: '../ajax/create_audit_standard_carosel.php',
type:'POST',
data: 'audit_id='+audit_id+'&user_id='+user_id,
dataType: 'json',
success: function(response){
$('#num').html(response.standards_count);
$('#standards_list').html(response.output);
jQuery(function($) {
$("#selected_standards").touchCarousel({
itemsPerPage: 4,
scrollbar: true,
scrollbarAutoHide: true,
scrollbarTheme: "dark",
pagingNav: false,
snapToItems: true,
scrollToLast: true,
useWebkit3d: true,
loopItems: false
});
});
}, // End of success function of ajax form
error:function (xhr, ajaxOptions, thrownError){
alert(thrownError);
}
}); // End of ajax call
響應是正確的,並且#standards_list
的內容已修改為正確的內容,因此我知道AJAX調用可以正常工作,但是成功調用中的功能將被完全忽略。
如果您的意思是該函數在更新#standards_list
元素之后立即開始,那是因為您試圖綁定到觸發了很長時間的事件。
將函數傳遞給全局jQuery函數是綁定到document.ready
事件的快捷方式。 加載頁面時將觸發此事件,並且不會因AJAX調用而再次觸發。
只需刪除包裝函數並在更新#standards_list element
后調用touchCarousel
方法#standards_list element
,例如:
$.ajax({
url: '../ajax/create_audit_standard_carosel.php',
type:'POST',
data: 'audit_id='+audit_id+'&user_id='+user_id,
dataType: 'json',
success: function(response){
$('#num').html(response.standards_count);
$('#standards_list').html(response.output);
$("#selected_standards").touchCarousel({
itemsPerPage: 4,
scrollbar: true,
scrollbarAutoHide: true,
scrollbarTheme: "dark",
pagingNav: false,
snapToItems: true,
scrollToLast: true,
useWebkit3d: true,
loopItems: false
});
}, // End of success function of ajax form
error:function (xhr, ajaxOptions, thrownError){
alert(thrownError);
}
}); // End of ajax call`
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.