skip to Main Content

When I initialize an ajax call, when the request is succeeded and match a condition I want to re-call it again inside it, like following:

$.ajax({
    ...
    success  :  function(){
                    if(true)
                        // run_this_request_again();
                },
    // or,
    complete : function(){
                    if(true)
                        // run_this_request_again();
                },
    ...
});

2

Answers


  1. Create a function and place you ajax code in it. Call that function wherever you required.

    function ajaxCall()
    {
        //Your ajax code here
        $.ajax({
            ...
            success:function()
            {
                if(true)
                    ajaxCall()
            },
            complete : function()
            {
                if(true)
                    ajaxCall()
            },
        });
    }
    
    Login or Signup to reply.
  2. You can call this inside success with the ajax method.

    $.ajax({
      success: function() {
        if (true)
          $.ajax(this);
      },
      complete: function() {
        if (true)
          $.ajax(this);
      }
    });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search