简体   繁体   English

ajax.actionlink与javascript首先调用

[英]ajax.actionlink vs javascript which calls first

I have a view that has an Ajax.Actionlink and at the same time, I have a .click event in javascript on the same Ajax.Actionlink. 我有一个具有Ajax.Actionlink的视图,同时,我在同一Ajax.Actionlink上的javascript中有一个.click事件。 When I click the action link, does the ajax run first or does the .click event in the javascript? 当我单击操作链接时,ajax是先运行还是在JavaScript中运行.click事件?

I would add examples, but I believe the question is clear enough 我会添加示例,但我相信问题已经很清楚了

Might it depend on where the .click event is bound? 可能取决于.click事件的绑定位置吗? Try adding a console.log() to both events and see which order they are called. 尝试将console.log()添加到两个事件中,并查看它们的调用顺序。

Well, what happens is that Ajax.ActionLink cancels the default action in order to send the ajax request. 好吧,发生的是Ajax.ActionLink取消了默认操作以发送ajax请求。 You might add the onclick event in the OnBegin option of Ajax.ActionLink . 您可以在Ajax.ActionLink的OnBegin选项中添加onclick事件。

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

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