与 YUI 2.7 同步 GET 请求?
我对 YUI 比较陌生 - 浏览他们很棒的文档,我没有找到同步加载外部资源的方法或标志。
或者反过来问问题; 对于每个匹配的节点,我需要调用一个方法,该方法在节点上插入一些内容; 对于异步调用,记住的标识符似乎混乱了。
因此,回调需要坚持
pid
调用函数的时间,而不是执行回调的时间 - 我说得对吗?
var platform_ids = YAHOO.util.Selector.query('.platform_id');
for (var i = 0; i < platform_ids.length; i++) {
var pid = platform_ids[i].getAttribute("id");
var sUrl = "/platform/" + pid + "/description/";
var callback = { success: function(o) {
document.getElementById(pid).innerHTML = o.responseText; }}
var transaction = YAHOO.util.Connect.asyncRequest(
'GET', sUrl, callback, null
);
}
谢谢。 MYYN
i'm relatively new to YUI - browsing their great docs, i do not find a method or a flag to load an external resource synchronously.
or the question the other way around; for each matched node i need to call a method, which inserts something at the node; with asynchronous calls the remembered identifiers seem to mess up.
therefore the callback need to stick to the
pid
when the function is called, not when the callback gets executed - am i getting this right?
var platform_ids = YAHOO.util.Selector.query('.platform_id');
for (var i = 0; i < platform_ids.length; i++) {
var pid = platform_ids[i].getAttribute("id");
var sUrl = "/platform/" + pid + "/description/";
var callback = { success: function(o) {
document.getElementById(pid).innerHTML = o.responseText; }}
var transaction = YAHOO.util.Connect.asyncRequest(
'GET', sUrl, callback, null
);
}
thanks.
MYYN
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不需要同步请求。 用户体验可能很糟糕。 您实际上只想将一个值传递给您的回调,以便它不依赖于
pid
(正如您所注意到的,当您的回调被调用时,它通常会具有不同的值):在这里,我使用
argument
回调成员来保存ID,并在回调函数本身中引用它,确保每个回调都使用正确的ID。You don't want a synchronous request. The user experience can be awful. You really just want to pass a value to your callback so that it's not relying on
pid
(which, as you've noticed, will usually have a different value when your callback is called):Here, I use the
argument
callback member to hold the ID, and reference that in the callback function itself, ensuring each callback uses the correct ID.