我正在处理一个HTML页面,该页面需要像以下方式提交POST请求并携带请求体到服务器:
<html>
<head>Customer app</head>
<body>
<div>
<table>
<tr>
<td>Customer Id :</td>
<td>
<form name="submitform" method="post">
<input type="text" id="customerId" name="customerId"/>
<input type="submit" value="Submit">
</form>
</td>
</tr>
</table>
</div>
</body>
<script>
$(document).ready(function(){
$("#submitform").click(function(e)
{
var MyForm = JSON.stringify($("#customerId").serializeJSON());
console.log(MyForm);
$.ajax({
url : "http://localhost:7777/ola-drive/customer/ride",
type: "POST",
data : MyForm,
});
e.preventDefault(); //STOP default action
});
});
</script>
</html>
出现404 Not Found错误并重定向到http://localhost:7777/customerapp.html,与请求提交相应的表单数据似乎是正确的,但它不能按预期工作。
有人能帮我修复我的HTML代码提交POST请求的重定向问题吗?