如何提高"完成"事件在提交的事件? [英] How to raise "completed" event on a submit event?

查看:144
本文介绍了如何提高"完成"事件在提交的事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

控制器操作的completedCallback后调用后不$(本).submit()。
请参阅下面的code。
我怎样才能触发动作提高完成回调,而无需使用AJAX之前?

控制器:



公众的ActionResult MyFunction的(的FormCollection数据){
//这个应该调用CompletedEvent之前触发
}

JavaScript的


VAR标志= FALSE;$(形式).submit(函数(){        如果(!标志){        //筹集启动事件
        startedCallback.call();        标志=真实的;
        $(本).submit();       //加薪完成事件
        completedCallback.call();}});


解决方案

如果你不想使用AJAX,你不能可靠地调用的东西后提交 - 表单的处理完成。如果你想要一个答复,您必须使用AJAX。

如果你想打电话给你的函数之前,你的表单提交 - 再次..你必须使用某种形式的Ajax

请参阅
我如何捕捉form.submit 响应

如果你真的需要像这样的活动的控制 - 你需要的AJAX或iframe黑客。抱歉:)

The controller action is called after the completedCallback not after $(this).submit(). See the code below. How can i trigger the action before raising the completed callback without using ajax?

controller:


public ActionResult MyFunction(FormCollection data){
//this should trigger before calling the CompletedEvent
}

javascript



var flag = false;

$(form).submit(function(){

        if(!flag){

        //raise start event
        startedCallback.call();

        flag = true;
        $(this).submit();

       //raise completed event
        completedCallback.call();

}

});


解决方案

If you do not want to use ajax, you cannot reliably call something after the submit - the form's processing is done. You must use ajax if you want a response.

If you want to call your function BEFORE your form submit - again.. you MUST use some form of ajax.

See How do I capture response of form.submit

If you really need control of events like this - you need ajax or iframe hacks. Sorry : )

这篇关于如何提高"完成"事件在提交的事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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