extjs中发送请求,参数以form表单形式上送
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<link href="https://cdn.bootcss.com/extjs/6.0.0/classic/theme-classic/resources/theme-classic-all.css" rel="stylesheet">
<script src="https://cdn.bootcss.com/extjs/6.0.0/ext-all.js"></script>
<script>
Ext.onReady(function(){
Ext.Ajax.request({
url: 'http://127.0.0.1:8101/user/test',
timeout:60000,
method : 'POST',//如果你没有设置这个配置项,但是存在请求参数,那么将会 使用"POST",否则将会使用"GET"。//这里测试了一下,GET\POST都是以form表单形式参数上送的
params: {
loginName:'zhangsan',
userName:'张三'
},
success: function(response){
console.log("响应内容:"+Ext.decode(response.responseText));
console.log("响应码:"+Ext.decode(response.responseText).code);
}
});
});
</script>
</head>
<body>
</body>
</html>
controller接收请求
@Api(description = "用于测试")
@RestController
@RequestMapping(value = "/user")
public class UserController {
@ApiOperation(value = "extjs test")
//RequestMapping接收GET\POST请求都可以
@RequestMapping(value = "/test")
public Result test(HttpServletRequest httpServletRequest) {
logger.info(httpServletRequest.getParameter("loginName"));
User user = new User();
user.setUserName("张三");
user.setLoginName("zhangsan");
return Result.res("0000","success",user);
}
}