【发布时间】:2015-12-06 15:39:42
【问题描述】:
如果 url 是手动分配的,例如 imgUrl="http://image.jpg" 它工作得很好,但如果它从后端使用 AJAX 函数“getRemote”接收它就没有。如果请求是异步的,它甚至不在这个块中,但如果它是同步的,它会被接收到,但 AR 对象不能使用它。任何想法为什么?
var imgUrl = getRemote();
this.img = new AR.ImageResource(imgUrl);
this.imgOverlay = new AR.ImageDrawable(this.img, 0.5, {
offsetX: 0,
offsetY: 0,
});
getRemote 函数:
function getRemote() {
return $.ajax({
type: "GET",
url: "http://someurl.php",
async: true
}).responseText;
}
【问题讨论】:
-
最好还是显示getRemote()代码,因为感觉错误可能在那个函数内。
-
当异步时,代码将在 AJAX 请求完成之前继续执行。我们可以看到
getRemote()方法的结果/代码吗?这可能是问题的根源
标签: javascript jquery ajax wikitude