简体   繁体   English

成功后,ajax没有调用另一个js函数

[英]ajax didn't call after success another js function

I am trying to make a ajax post. 我正在尝试发布ajax帖子。 I just want to learn how can i call some function after ajax success. 我只想学习ajax成功后如何调用某些函数。

I want to call the following function after ajax success: 我想在ajax成功之后调用以下函数:

function col() {
        var $container = $(".post-users-body");
        $container.imagesLoaded(function() {
            $container.masonry({
                columnWidth: ".collectionPostWrap",
                itemSelector: ".collectionPostWrap"
            });
        });
}

The ajax post is this: Ajax帖子是这样的:

$("body").on("click","#update_button",function() {
    var updateval = $("#update").val();
    var dataString = 'update=' + updateval ;
      $.ajax({
        type: "POST",
        url: "requests/post.php",
        data: dataString,
        cache: false,
        success: function(html) {
          $(".post-users-body").prepend(html);
          col();            
        }
      });

    return false;
  });

So the ajax post is working fine but it is not calling the col(); 因此,ajax发布工作正常,但未调用col(); function. 功能。

What i am doing wrong here. 我在这里做错了。 Anyone can tell me ? 有人可以告诉我吗?

ajax returns a promise object. Ajax返回一个Promise对象。 use that and do some function chaining. 使用它并执行一些功能链接。

    <script>
        (function(){

            function col(){
                alert("col called");
            }

            $.ajax({
                type:"GET",
                url:"http://localhost:5850/api/someservice"}
             ).done(function(){
                    debugger;
                    col();
                });
        })()



    </script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM