我正在使用第8墙SDK并尝试调用API。当我尝试通过AFrame.registercomponent onclick方法执行此操作时,请求未被发送。
我是AR的新手。当我尝试为xhttp添加警告消息时,它是空的。
我遗漏了什么?
有没有别的选择呢?
顺便说一句,我试着用Awe.js的AR标记来做这件事,它工作得很好。
AFRAME.registerComponent('play-on-window-click', {
...
...
onClick: function(evt) {
var video = this.el.components.material.material.map.image;
// I'm sending a request from here - BEGIN
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.status == 200) {
this.responseText;
}
xhttp.open("GET", "https://myapi/rest/abc", true);
xhttp.send();
}
// END
video.play();
}
}我期望对API的调用成功。
发布于 2019-04-06 01:05:36
xhttp.open和xhttp.send调用在onreadystatechange处理程序中,因此它不会被发送。像这样的东西应该是有效的:
AFRAME.registerComponent('play-on-window-click', {
...
...
onClick: function(evt) {
var video = this.el.components.material.material.map.image;
// I'm sending a request from here - BEGIN
var xhttp = new XMLHttpRequest();
http.onreadystatechange = function() {
if (this.status == 200) {
alert(this.responseText);
}
}
xhttp.open("GET", "https://myapi/rest/abc", true);
xhttp.send();
// END
video.play();
}
}https://stackoverflow.com/questions/55527649
复制相似问题