春季启动和JavaScript XMLHTTPRequest()

时间:2018-11-26 01:06:52

标签: javascript java spring-boot

此问题不是重复的,指向其他问题的链接不能解决此问题。带弹簧启动!我正在尝试使用javascript xmlhttprequest()获得响应,但是在我的jsp中却得到了空白响应。我想得到“ hi”作为回应,我该怎么做才能使其在Spring Boot中正常工作?

我的控制器:

  @Controller
public class Intro2 {
    @ResponseBody
    @RequestMapping(value = "/intro2", method = RequestMethod.GET)
    public String show(){
        return "hi";
    }

我的jsp:

var xhttp = new XMLHttpRequest();

  xhttp.open("GET", "localhost:8080/intro2", true);
  xhttp.send();
  var text = xhttp.responseText;
  var target = document.getElementById("main");
  target.innerHTML = text;}

0 个答案:

没有答案