jquery abort() ajax request before sending another

前端 未结 4 1056
庸人自扰
庸人自扰 2020-11-29 21:54

Based on: Abort Ajax requests using jQuery... In inventory_search() - before the ajax request is made, how can I check for any current requests and abort() them before makin

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-29 22:13

    Use a global variable to hold the handle of the current request. In this case declare the var a out side the function and make it global. Before calling the ajax check it is not null. If it is not null abort it other wise assign it with new ajax. In the success/complete event make sure you clear the variable a. May not be best solution out there, but works best.

提交回复
热议问题