简体   繁体   English

如何使用Jquery.Unobtrusive.Ajax取消Ajax请求?

[英]How to cancel ajax request using Jquery.Unobtrusive.Ajax?

I'm using Ajax.ActionLink like this 我正在像这样使用Ajax.ActionLink

@Ajax.ActionLink("link text", "action", new AjaxOptions(){ OnBegin = "test()" })

I want to be able to cancel the ajax call of the link based on the result of my test() function in javascript, like so 我希望能够根据我在javascript中的test()函数的结果来取消链接的ajax调用,就像这样

function test(){

  if(condition){
    //execute the ajax request 
    return true; 
  }else
  {
    //cancel the ajax request
    return false; 
  }

}

I've seen tutorials demonstrating that this is possible, but I somehow can't get it to work.Can someone help me with that? 我看过一些教程证明这是有可能的,但是我莫名其妙地使它无法工作,有人可以帮我吗? Thanks! 谢谢!

Change 更改

OnBegin = "test()"

to

OnBegin = "return test()"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM