Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript ajax中的调用函数成功_Javascript_Jquery_Ajax - Fatal编程技术网

Javascript ajax中的调用函数成功

Javascript ajax中的调用函数成功,javascript,jquery,ajax,Javascript,Jquery,Ajax,我试图从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(respons

我试图从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元素
后删除包装功能并调用
touchCarousel
方法,例如:

$.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`

到底什么被完全忽略了?您是否完成了任何console.log?图像将上载到服务器,并以列表形式显示,布局由旋转木马功能设置样式。图像上传正常,显示在列表中,但由于旋转木马功能未加载,因此旋转木马的样式不正确。如果我手动刷新页面,旋转木马函数会加载,因为它也在页面上为什么
jQuery(函数($){
…?@CBroe因为我还在学习,似乎是我弄错了,你的解释在这里不正确。如果你调用jQuery的
.ready()
在它触发后,它将立即调用您的回调。它将调用它。也就是说,根本没有理由将此代码包装在jQuery的就绪逻辑中,因为文档已经加载-尽管我不知道这实际上是如何导致OP问题的。通常是的,触发事件后绑定到就绪事件将触发绑定函数必须立即调用,但AJAX响应或事件的处理方式中必须存在阻止它的因素