簡體   English   中英

從ajax webservice調用的OnComplete調用ajax webservice不會第二次觸發OnComplete

[英]Calling ajax webservice from OnComplete of an ajax webservice call not firing OnComplete 2nd time

我在ASP.NET內容頁面的javascript(mootools)中使用Masterpage從javascript(mootools)調用了一個經過修飾的.NET Web服務,首先檢查用戶是否與新聞工作者相關聯,其次如果沒有新聞工作者與新聞工作者相關聯,則刪除該用戶。

兩次都調用了webservice,但是第二次的onComplete在IE8中不起作用。 使用FF 3.5.3,我在Firebug中收到“未定義deleteUserInt”錯誤。

我已經讀過這可能是一個語法錯誤,但似乎看不到它。

請幫忙。

var userId;
var siteName;
var siteFolder;
function userInternalHasUserExternals() {
    siteName = document.location.href.split("/")[document.location.href.split("/").length - 1];
    siteFolder = document.location.href.replace(siteName, "");
    var jsonRequest = new Request.JSON({ url: siteFolder + "Service1.asmx/UserInternalHasUserExternals",
        onComplete: onComplete,
        onFailure: onError,
        urlEncoded: false,
        headers: { "Content-type": "application/json" }
    });
    userId = document.getElementById("<%= HiddenId.ClientID %>").innerText;
    jsonRequest.send(JSON.encode({ 'userInternalId': userId }));
}

function onComplete(results) {
    var fullname = document.getElementById("<%= fullnameTextBox.ClientID %>").value;

    if (results != null && results["d"] != null && results["d"]) {
        alert("Du kan ikke slette " + fullname + ". Kontoen har journalister tilknyttet.");
        return false;
    }

    var deleteUser = confirm("Er du sikker på du vil slette " + fullname + "?");
    if (deleteUser) {
        deleteUserInt();
        window.location = window.siteFolder + "CreateUserInternal.aspx?IsDeleted=true";
    } 
    else
        window.location = window.siteFolder + "EditUserInternal.aspx?UserInternalId=" + window.userId;
}

function deleteUserInt() {
    var request;
    request = new Request.JSON({ url: window.siteFolder + "Service1.asmx/DeleteUserInternal",
        onComplete: onDeleted,
        onFailure: onError,
        urlEncoded: false,
        headers: { "Content-type": "application/json" }
    });
    request.send(JSON.encode({ 'userInternalId': window.userId }));
}

function onDeleted(args) {
    if (args != null && args["d"] != null && args["d"])
        window.location = window.siteFolder + "CreateUserInternal.aspx?IsDeleted=true";
    else
        alert("Der skete en fejl. Kontakt venligst site administrator.");
}

function onError() {
    alert("Something bad happened!");
}

當我將javascript移出文件並使用innerText而不是innerHTML發現錯誤時,此問題已“解決”。

IE8丟失的函數在移動后也被稱為“固定”自身。

當然,我必須傳遞ClientIds,我在aspx頁面中將其用作新方法的參數,但這對我來說很好用。

出於某種原因,當我有2個確認和一個警報時,Firefox會開槍。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM