笑故挽风 2019-07-14 20:49 采纳率: 100%
浏览 27

无法连接html

“I’m trying to make an Ajax call, which is successful. But when I try to print the response it does not concatenate the "success" or "failure: string with "initial value"

it prints the middle vale and Also, if i put console.log inside success or failure it prints the value. It does not work outside the Ajax call

loadData : function(groupRID, serviceName) {
    var html = 'initial value';
    var params = {
        codeGroupRid : groupRID,
        outputFormat : 'json'
    };
    html +=' middle'
    Util.Functions.eAjax(serviceName, params, {
        success : function(response) {
            html += ' Success';
            return html;
        },
        failure : function(errMsg) {
            html += ' Failure';
            return html;
        }
    });      
},

Expected is - initial value middle Success

Actual is - initial value middle

  • 写回答

2条回答 默认 最新

  • weixin_33743248 2019-07-15 09:10
    关注

    Remove the return html; part from success and failure callbacks cause ajax is asynchronous. If you use return inside the callback it return before response is obtained.

    评论

报告相同问题?