我已在HTML中以下REST @FormParam值均爲空
<form name="myform" method="POST">
<input type="text" id="products" name="products" />
</form>
function myForm() {
var url = 'rest/products/details/';
var formData = $("#myform").serializeArray();
$.ajax({
url: url,
type: 'POST',
contentType : "application/x-www-form-urlencoded",
dataType: 'json',
data: formData,
success: function (data) {
//callfunc(data);
}
});
}
在Java服務器端我有以下
@POST
@Path("/details")
public List<Product> findProducts(@FormParam("products") String products) {
.....
.....
log.info("prod "+products); --> getting null
出於某種原因,產品爲空,即使我傳遞正確的價值觀來自html。這可能是什麼原因?
嘗試['serialize()'](https://api.jquery.com/serialize/),而不是['serializeArray()'](https://api.jquery.com/serializeArray/)。你做了一個'console.log(formData)'來看看它看起來像什麼嗎? –