jquery回调令人头痛
下面的调用 getData() 返回 populateForm() 方法所依赖的 Javascript。
如果出现警报,则存在来自 getData() 的正确 js 方法。如果没有警报,我会收到一个 js 错误,表明这些方法不存在。
它适用于存在的警报。没有它就会失败。我似乎无法通过回调正确捕获它。任何帮助表示赞赏 -
我怎样才能使它工作?
elqTracker.getData({
key: contactLookup,
lookup: "<C_EmailAddress>" + getCookie('c_Email') + "</C_EmailAddress>",
success: function() {
//alert('---' + getCookie('c_Email'));
populateForm(formName);
trackPage().done(function(guid) {
$('#elqCustomerGUID').val(guid);
});
}
});
The call getData() below returns Javascript that the populateForm() method depends on..
With the alert the proper js methods from getData() are present.. Without the alert I get a js error that those methods are not present.
It works with the alert present.. FAILS without it.. I can't seem to trap it correct with a callback.. Any help is appreciated -
How can I make it work?
elqTracker.getData({
key: contactLookup,
lookup: "<C_EmailAddress>" + getCookie('c_Email') + "</C_EmailAddress>",
success: function() {
//alert('---' + getCookie('c_Email'));
populateForm(formName);
trackPage().done(function(guid) {
$('#elqCustomerGUID').val(guid);
});
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对
getData()
调用实际执行的操作一无所知,但如果添加alert()
突然使事情正常工作,那么可能是因为您有一个异步操作,没有正确等待完成。添加alert()
使其工作,因为异步调用在alert()
在屏幕上时完成,因此它会在之后的下一行之前完成执行alert()。
getData()
调用的文档中必须有一些内容告诉您如何成功等待它完成。显然成功回调还不够。如果
getData()
调用正在加载 javascript,如您在评论中所述,那么您可能需要等待该 javascript 完成加载。完成后,也许有一个不同的回调需要挂钩。I know nothing about what the
getData()
call actually does, but if adding thealert()
suddenly makes things work, then it's probably because you have an asynchronous operation that you are not correctly waiting for the completion of. Adding thealert()
makes it work because the asychronous call completes while thealert()
is on screen so it eds up being done before the next line after thealert()
executes.There has to be something in the documentation for your
getData()
call that tells you how to successfully wait for it to be completed. Apparently the success callback isn't enough.If the
getData()
call is loading javascript as you said in your comment, then you may need to wait for that javascript to finish loading. Perhaps there is a different callback to hook when that is complete.