如何解决Whyt Jquery Ajax发布不适用于HtmlUnit
我正在将htmlunit与spring test一起使用,以便从Web应用程序测试所有ihm接口。 html格式(post和get)和ajax get都可以正常工作,但是我对ajax post请求有问题。
控制器未收到请求。如果我替换为junit测试用例,则工作正常。
这是html视图
<html lang="fr" xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head>
<title>Spring Html Unit</title>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
<script>
function postTest() {
$.ajax({
type:"post",data: {
'subject' : 'subject test','message' : 'message test'
},url:"[[@{/test/post}]]",success: function(data,textStatus,jqXHR){
$("#result").text(data);
}
});
}
</script>
</head>
<body>
<h4 th:text="'Hello to Thymeleaf '+${myParam}">Hello from Thymeleaf</h4>
<button type="button" onClick="postTest()">Test post</button>
<div>
<span>result :</span><span id="result"></span>
</div>
</body>
和控制器
@控制器 公共类WelcomeController {
@GetMapping("/")
public String init(Model model) {
model.addAttribute("myParam","Guillaume");
return "welcome";
}
@PostMapping("/test/post")
public @ResponseBody String post(@RequestParam String subject,@RequestParam String message,Model model) {
return subject + " " + message;
}
}
您还可以在我的github https://github.com/guisimon28/spring-test-htmlunit
上找到完整的代码。您能帮我找到是否缺少某些配置,或者它是否是htmlunig错误或请求请求吗?
感谢所有人
纪尧姆
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。