2015-02-07 39 views
0
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; 
          }) 
    } 
} 

上面代码中的问题是我的页面在插入google日历信息之前被重定向。这是因为我知道jQuery代码不会逐行执行,并且在完成Google日历事件之​​前,重定向代码被触发并且Google日历记录未被插入。 任何帮助将不胜感激。从MVC调用jquery函数操作方法

谢谢

+0

你可以发布insertgoogleevent代码吗? – 2015-02-07 07:26:01

+0

标题和问题似乎是矛盾的:) – 2015-02-07 07:42:56

+0

我写了这个标题,因为如果我可以从mvc action调用javascript,那么在脚本执行完成之前,页面重定向不会发生。 – 2015-02-17 06:35:21

回答

0

看来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; 
         }) 
} 
} 
+0

您还需要在insertgoogleevent函数的回调函数 – 2015-02-07 07:35:41

+0

中放置window.location.href我无法这么做,因为我在另一个页面中也使用了相同的脚本。 – 2015-02-17 06:32:13

+0

@NadeemShaikh然后,你需要添加一些标志函数参数来确定谁是来电者,并使如果基于条件bahaviour在那里。 – 2015-02-17 06:48:28