1

I'm a noob with this stuff(so please be patient), All i want to do is execute a function after the API is completely done, at the moment the JavaScript is posting and reading at the same time giving me unwanted results.

        function getData() {
            return $.ajax({ type: "POST", 
            data: JSON.stringify(test), 
            url:"/api/answers/", 
            contentType: "application/json" 

So I read this article jQuery ajax success callback function definition

and did this

        var timer = $.Deferred();
        setTimeout(timer.resolve, 5000);
        var jaax = getData().done();
        $.when(timer, jaax).done(this.Seven());

This doesn't work since it calls function Seven anyways while its posting

I also tried this Ajax call function after success:

      $.ajax({ type: "POST",
         data: JSON.stringify(test), 
         url: "/api/answers/", 
         contentType: "application/json" ,
         success: Seven
          } ); }

And that just gave my soul pain as it calls function Seven while posting, What am i missing? why is it not working?

Community
  • 1
  • 1
Jack
  • 526
  • 3
  • 10
  • 30

1 Answers1

2

try this

getData().done(function(results){
    // results are what retuned from the server
    Seven();
});
Nerdroid
  • 13,398
  • 5
  • 58
  • 69