我正在尝试对通过java托管的本地URL进行AJAX调用。该URL目前只包含一个字符串。ajax调用映射的URL
但是,当我尝试从我的JavaScript调用它,我没有得到任何返回值。代码/ URL甚至不起作用。
的Javascript代码(网站):
var xhr = new XMLHttpRequest();
xhr.onload = function() {
if(true){
alert('hello!');
document.getElementById('newgame').innerHTML = xhr.responseText;
}
};
xhr.open('GET', 'localhost:8080/highscore', true);
xhr.send(null);`
JAVA类代码(当前运行):
@RestController
public class Server {
@RequestMapping("/highscore")
public String highScore() {
return "test";
}
}
我试过了,它仍然不起作用。 –