gpt4 book ai didi

javascript - location.href 在 ajax 之后不起作用(更多详细信息)

转载 作者:行者123 更新时间:2023-12-03 01:15:05 24 4
gpt4 key购买 nike

当ajax调用成功时,执行回调函数。回调函数中的函数无论如何都不起作用。

我的代码是:

    sendAjax(url, data, method, async, callBackFn, IgnoreException) {
$.ajax({
type:method,
async:async,
url:url,
data:data
timeout:timeout,
beforeSend:function(xmlHttpRequest) {
xmlHttpRequest.setRequestHeader("AJAX", "true");
},
success:function(data) {
try {
var responseText = $.parseJSON(data);
if (responseText.error_code && !IgnoreException) {
alert(responseText.error_msg);
var fnName = responseText.LOGIN||{};
if (typeof window[fnName] == 'function') {
var args = responseText.LOGIN_PARAM||{};
window[fnName](args);
}
} else {
callBackFn($.parseJSON(data));
return;
}
} catch(e) {
~~~~~~~~~
} finally {
}
}

})

}

。。。.

sendAjax("mo/serviceAction.do", $("#form").serialize(), "post", true, callback);

。。。.

function callback(param) {
alert("Here!");
location.href = "intent://host&params#intent;scheme='scheme';package=package";
}

但是,如果在 ajax 调用后未执行的函数作为按钮标签上的单击事件执行,则执行 location.href...但是,警报(“这里!”)正在工作!!

为什么两种情况不同?

如果我想直接在回调中运行 location.href 该怎么办?

最佳答案

您将 allBackFn 作为参数名称存在拼写错误。

sendAjax(url, data, method, async, acllBackFn, IgnoreException)

稍后。

callBackFn($.parseJSON(data));

关于javascript - location.href 在 ajax 之后不起作用(更多详细信息),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52051712/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com