php - How can I retry an ajax request on empty response -
i retry ajax request when response data empty json object.
my ajax code following.
$.ajax({         type: "post",         url: "index.php?r=funding/getpaymentbutton",         data: {email:benfemail,data:json.stringify(data),paymenttype:method},         async: true,//false         success: function (data)          {              if(data.length === 0)             {                 $(this).ajax();//retry ajax request here, if data empty                 console.log('err');             }             else             {                 obj = jquery.parsejson(data);                 // prcessing ajax request             }         } });   php
echo json_encode(array(     'type'=>$paymenttype,      'btn'=>$this->paymentbtn,     'usd' => round($this->finalusdamount,2),) );      
you can put ajax request in function , call function if respons empty.
like this:
 function yourcall(){      $.ajax({         type: "post",         url: "index.php?r=funding/getpaymentbutton",         data: {email:benfemail,data:json.stringify(data),paymenttype:method},         async: true,//false         success: function (data)          {              if(data.length === 0)             {                yourcall();                console.log('err');             }             else             {                 obj = jquery.parsejson(data);                 // prcessing ajax request             }         }     });  }   this setup keep trying ajax call untill gets valid respons. meaning keep firing if respons length == 0
Comments
Post a Comment