2015-02-07 31 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

相關問題