简体   繁体   English

从MVC Action方法调用jquery函数

[英]Call jquery function from MVC Action method

function AddScheduledCandidate() {

if (ValidateScheduledCandidate()) {
    InsertGoogleEvent($('#comment').val(), $('#SchDateTime').val() );

    $.post(WebsiteURL + 'VideoRepository/AddScheduledCandidate', { id: $('#hdnId').val() }, "json")
                            .done(function (response) {

                                    window.location.href = response.Url;
                            })
    }
}

The problem in above code is that my page is redirected before google calender info is inserted. 上面的代码中的问题是,在插入Google日历信息之前,我的页面已重定向。 It is because I know jquery code doesn't execute line by line and before completing google calendar event, redirect code is fired and google calendar record is not inserted. 这是因为我知道jquery代码不会逐行执行,并且在完成Google日历事件之​​前,会触发重定向代码并且不会插入google日历记录。 Any Help will be highly appreciated. 任何帮助将不胜感激。

Thank you 谢谢

It seems insertgoogle event is async server call so try something like below to sync call . 看来insertgoogle事件是异步服务器调用,因此请尝试以下类似操作来同步调用。

function AddScheduledCandidate() {

if (ValidateScheduledCandidate()) {


$.post(WebsiteURL + 'VideoRepository/AddScheduledCandidate', { id: $('#hdnId').val() }, "json")
                        .done(function (response) {

 InsertGoogleEvent($('#comment').val(), $('#SchDateTime').val() );
                           window.location.href = response.Url;
                        })
}
}

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

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