0
我想从github获取访问令牌,但首先我必须登录。所以我提出了我的要求,并且我得到了一个html页面作为答案,以及如何将其显示给用户? 我的JavaScript变量包含整个html,所以如何向用户显示这个html页面? (这对我来说并不重要,如果它是弹出窗口或在同一页面上) 任何答案是赞赏:),网络开发对我来说是新的。如何向用户显示html页面响应?
客户:
$.ajax({
url: localhost + "user/",
cache: false,
success: function(html){
console.log("success");
}
});
服务器:
@GetMapping("/user")
public @ResponseBody ResponseEntity<?> user() {
RestTemplate rt = new RestTemplate();
Map<String, String> map = new HashMap<String, String>();
map.put("client_id", "12356....");
map.put("redirect_uri", "http://localhost:5000/DashboardApp/app/index.html#/home");
ResponseEntity<String> response = rt.getForEntity("https://github.com/login/oauth/authorize", String.class, map);
System.out.println(response);
return response;
}
//What I get as a response :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta content="origin" name="referrer" /> ...
'angular.js:13920语法错误:意外标记<在JSON在位置0 在JSON.parse()'这是我得到的,如果我不使用$ ajax –
Oleg
@Oleg这是因为$ http期望JSON并解析它。你正在返回一个html页面。 $ .ajax直接使用返回的结果。 –
@StefanKert谢谢Stefan,我猜这个html页面是我需要的,因为用户希望看到github登录页面,所以如何向他显示这个页面? – Oleg