带有表单序列化的Ajax请求

时间:2018-07-12 22:11:02

标签: ajax forms jsp

我有一个jsp,格式如下:

<form action="updateServlet" id="beam" method="POST">
    <input type="text" name="length" id="length" value="${beam.length}"<br>
    <input type="text" name="pinLocation" id="pinLocation" value="${beam.pinDistance}"<br>
    <input type="text" name="rollerLocation" id="rollerLocation" value="${beam.rollerDistance}"><br>
    <input type="button" id="ajaxButton" onclick="" value="AjaxSolve"></input>
</form>

加上其他字段是动态生成的。我想使用ajax异步提交它:

$(document).on("click", "#ajaxButton", function() { 
var form = $("#beam");
$.ajax({
 type: "post",
 url: "updateServlet",
 data: form.serialize(),
 success: function(){alert("success");},
 error: function(){alert("error");}
 });   
});

不幸的是,我一直收到此错误:

  

“无法加载资源:服务器响应状态为500(内部服务器错误)”

我对form.serialize()发出了警报,它正常工作。

此外,如果我使用普通的JSON数据(data: {name : "SOMETHING}),而不是提交序列化的表单,则提交会成功。因此,我很确定这是数据问题:form.serialize(),行。

0 个答案:

没有答案
相关问题