0

我有一个表单,它调用一个过程 onsubmit,这个过程解析文档并创建一个传递给适配器的 json 对象。似乎当 onSubmit 过程结束时,对适配器的调用被终止,然后调用适配器的 onFailure 方法。

我的问题是如何在我的 onSubmit 过程中等待适配器完成。

如果我在 onSuccess 中添加一个标志并等到该标志被设置,我将不会捕捉到真正的失败。如果我在 onFailure 中添加一个标志,因为由于进程被杀死而调用 onFailure,我将无法等待进程结束。

如果我在 onSubmit 过程中调用适配器后添加警报并等待触发 onSuccess ,则它可以工作......

这里有一些代码:

function postCustomer(content) {
    var invocationData = {
        adapter : 'myAdapter',
        procedure : 'postCustomerByContent',
        parameters : [ content ]
    };

    WL.Client.invokeProcedure(invocationData, {
        onSuccess : postCustomerSuccess,
        onFailure : postCustomerFailure,
        timeout: 30000
    });
}

function postCustomerSuccess(result) {
    var httpStatusCode = result.status;
    if (200 == httpStatusCode) {
        var invocationResult = result.invocationResult;
        var isSuccessful = invocationResult.isSuccessful;
        if (true == isSuccessful) {
            WL.SimpleDialog.show('Title', "Success", [{text : 'OK'}]);
        } else {
            WL.SimpleDialog.show('Title', "Error. isSuccessful=" + isSuccessful, [{text : 'OK'}]);
        }
    } else {
        WL.SimpleDialog.show('title', "Error. httpStatusCode=" + httpStatusCode, [{text : 'OK'}]);
    }
}

function postCustomerFailure(result) {
    WL.SimpleDialog.show('Title', "Failed:"+result, [{text : 'OK'}]);
}

function formSubmit() {
    var application = document.forms["application"], initial = application["ibmerName"].value, email, name, organizationName = application['organizationName'].value, primaryContactName = application['primaryContactName'].value, primaryContactEmail = application['primaryContactEmail'].value, organizationAddress = application['organizationAddress'].value, primaryContactPhoneNumber = application['primaryContactPhoneNumber'].value, country = application['country'].value, organizationType = application['organizationType'].value;
    if (initial == "xxx") {
        email = "xxxxxxxxxxxxxxxxx";
        name = "xxx";
    } else if (initial == "yyy") {
        email = "yyyyyyyy";
        name = "yyyyyyyyyy";
    } else {
        email = "xxxxxxxxxxxxxxxxxx";
        name = "xxxxxxxxxxxxxxxxx";
    }
    var content = '{"email":"' + email + '","name":"' + name
            + '","organizationName":"' + organizationName
            + '","primaryContactName":"' + primaryContactName
            + '","primaryContactEmail":"' + primaryContactEmail
            + '","organizationAddress":"' + organizationAddress
            + '","primaryContactPhoneNumber":"' + primaryContactPhoneNumber
            + '","country":"' + country + '","organizationType":"'
            + organizationType + '"}';
    postCustomer(content);

    alert(content);

}

任何想法?谢谢

4

1 回答 1

0

是否刷新页面,如果是这样,您必须在 formSubmit 函数的末尾执行 return false 。

于 2013-10-02T18:30:51.757 回答