ajaxStart和ajaxStop特定事件 [英] ajaxStart and ajaxStop for a specific event

查看:189
本文介绍了ajaxStart和ajaxStop特定事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何绑定一个 ajaxStart 函数的特定事件,使用:

  $(文件).ajaxStart(函数(){
  警报(开始);
});
$(文件).ajaxStop(函数(){
  警报(截止);
});
 

试过这种code,但它运行时自动完成启动。

方案必须是这样的:每当我提交表单,该函数将被调用。 但是,当我只是通过获取使用AJAX自动完成的值, ajaxStart ajaxStop 不应该被调用。

解决方案

  $。阿贾克斯({
      网址:您的网址,
      数据: {
           //数据如有送
      },
      键入:POST,
      成功:函数(MSG){
           //如果确定EQV到ajaxstop
      },
      beforeSend:函数(){
           //阿贾克斯开始之前
      },
      错误:函数(){
           //在阿贾克斯失败
      }
 });
 

How can I bind an ajaxStart function for a specific event, using :

$(document).ajaxStart(function () {
  alert("started");
});
$(document).ajaxStop(function () {
  alert("Ended");
});

Tried this code but it runs whenever autocomplete starts.

Scenario must be like this : whenever I submit a form, that function will be called. But when I'm just fetching values using autocomplete via ajax, ajaxStart and ajaxStop shouldn't be called.

解决方案

 $.ajax({
      url :'your url',
      data: {
           //data to send if any
      },
      type: 'POST',
      success:function(msg){
           //eqv to ajaxstop if OK
      },
      beforeSend:function(){
           //before ajax starts
      },
      error:function(){
           //failure in ajax
      }
 });

这篇关于ajaxStart和ajaxStop特定事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆