Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Ember从Spring获取HTML页面。如何请求html页面?_Spring_Ember.js_Ember Cli - Fatal编程技术网

如何使用Ember从Spring获取HTML页面。如何请求html页面?

如何使用Ember从Spring获取HTML页面。如何请求html页面?,spring,ember.js,ember-cli,Spring,Ember.js,Ember Cli,我在春天有一个login.html页面。我有一个控制器在8080端口为这个页面服务。如何使用余烬获取此完整页面 这是我的控制器: @Controller public class LoginController { LoginService loginService; public LoginController(LoginService loginService) { this.loginService = loginService; }

我在春天有一个login.html页面。我有一个控制器在8080端口为这个页面服务。如何使用余烬获取此完整页面

这是我的控制器:

@Controller
public class LoginController {

    LoginService loginService;

    public LoginController(LoginService loginService) {
        this.loginService = loginService;
    }

    @RequestMapping("/login")
    public String showJoke(Model model){

        model.addAttribute("date",loginService.getDate());

        return "login";
    }
}
这是我的余烬我将如何显示此页面

import Controller from '@ember/controller';

export default Controller.extend({

    init: function () {
        this._super(... arguments)

        let httpRequest = new XMLHttpRequest();
        httpRequest.onreadystatechange = () => {

            if(httpRequest.readyState==4 && httpRequest.status==200){
                console.log("ok");
            }

        }

        httpRequest.open("GET","http://localhost:8080/login",true);
        httpRequest.send();
    }

});

您可以获取数据并在控制器上进行设置,然后将其显示在模板中,如下所示:

app/controllers/application.js

app/templates/application.hbs


我在这里使用fetch API是因为我对它比较熟悉,但无论您如何提取数据,操作都是相同的。

请添加有关您试图完成的操作的其他详细信息。我不确定您是否试图向用户显示登录页面,或者是否希望解析该页面中的某些数据,或者完全使用第三个选项。我只是尝试从spring获取一个html页面并显示它。Ember将发出一个http请求,响应将是一个html页面。我将如何使用余烬显示该页面。我知道这是个坏主意,我只是想知道怎么做。
import Controller from '@ember/controller';
import fetch from 'fetch';

export default Controller.extend({
  htmlData: null,

  init: function () {
    this._super(... arguments)
    fetch('http://localhost:8080/login').then(response => {
      this.set('htmlData', response.text());
    }); 
  }
});
{{this.htmlData}}