Has been submitted to the wrong I don't know is my front ajax problem or the backend interface code I put all hope bosses help me to solve crab crab
The front-end ajax request:
layui. $. Ajax ({
BeforeSend: function (request) {
Request. SetRequestHeader (" Accept ", "application/json);
//request. SetRequestHeader (" Access - Control - Allow - the Methods: POST, GET ");
Request. SetRequestHeader (' the content-type ', 'application/json);
},
Url: 'http://www.xxx.net.cn:30334/ArchiveHNBackend/person/platform',//here is the address
Type: "get",
DataType: "json",//cross domain
CrossDomain: true,
//contentType: "application/x - WWW - form - urlencoded; Charset=utf-8,
"//the json: "callback",
Data: {" name ": data. PersonName},
Success: the function (data) {
console.log(data);
}
});
Backend interface code
@ RequestMapping ("/platform ")
Public void platformList (@ RequestParam String name, it request, HttpServletResponse response) {
/* PageHelper. StartPage (1, 100);
ListList=personService. PlatformList (name);
PageInfo PageInfo=new PageInfo (list);
Return ResultGenerator. GenSuccessResult (pageInfo); */
String token="";
The Users Users=null;
The users=usersService. FindByUserName (UNAME);
Long time=System. CurrentTimeMillis ();
String subject=users. GetUsername () + ", "
+ users. GetRealname () + ", "
+ users. GetRoleid () + ", "
+ users. GetId () + ", "
+ users. GetDeptid ();
Token=Jwts. Builder ()
. SetSubject (subject)
//set the expiration time 1 * 24 * 60 * 60 seconds to modify)
SetExpiration (new Date (time + JwtConfig. Time))
//by what algorithm can choose their own, not necessarily using HS512
SignWith (SignatureAlgorithm HS512, JwtConfig. SIGNING_KEY)
The compact ();//compressed into XXXX, XXX format
UserDto u=new UserDto ();
U.s etToken (token);
Try {
Redis. SetStr (users. GetUsername (), token);
} the catch (Exception e) {
e.printStackTrace();
}
//the log. The info (" user "+ users. GetUsername () +" landing ");
Try {
The response. SendRedirect (URL + "token=" + token + "& amp; Code="+ 200 +" & amp; Homepage=Dashboard "+" & amp; Condition="+ name);
The response. SetHeader (" Access - Control - Allow - Origin ", "http://localhost:6223");
The response. SetHeader (" Access - Control - Allow - Credentials ", "true");
//solve the cross-domain
//getJsonpData (request, response);
System. The out. Println (response);
} the catch (IOException e) {
e.printStackTrace();
}
}
CodePudding user response:
Do you have any elder brother ah help heart tiredCodePudding user response:
Methods in the background with @ CrossOrigin annotations to try
The import org. Springframework. Web. Bind. The annotation. CrossOrigin;
@ CrossOrigin
@ RequestMapping ("/platform ")
Public void platformList (@ RequestParam String name, it request, HttpServletResponse response) {
/* PageHelper. StartPage (1, 100);
ListList=personService. PlatformList (name);
PageInfo PageInfo=new PageInfo (list);
Return ResultGenerator. GenSuccessResult (pageInfo); */
String token="";
CodePudding user response:
I also am this problem, notCodePudding user response:
There's a cross domain annotation on the controller layer is like @ Crs to know under what did baidu