[英]jquery doesn't submit the form
this is the button in jsp page: 这是jsp页面中的按钮:
<button id="saveProperty" name="saveProperty" class="btn btn-primary btn-sm" type="button"><spring:message code="be.ashblerje.personsave"/></button>
I don't know why jquery doesn't submit the form: 我不知道为什么jquery不提交表单:
when the type of button is submit the form gets submits, but I dont want to be submitted in that way. 当按钮的类型为提交时,表单将被提交,但我不想以这种方式提交。 when i make the submit as above and the type button it doesn't do anything.
当我如上所述进行提交和类型按钮时,它什么也没做。
$('#saveProperty').click(function(event) {
var url = getAppContextPath() + 'propertyExist';
var nameproperty = $("#nameproperty").val();
var address = $("#address").val();
$.ajax({
type: "POST",
url: url,
data: {
nameproperty: nameproperty,
address: address
},
success: function(data) {
if (data) {
alert("Property already exist!");
event.preventDefault();
} else {
$("#formProperty").submit();
}
}
});
});
if you want to send json data to server by ajax, you must add properties like this: 如果要通过ajax将json数据发送到服务器,则必须添加如下属性:
$.ajax({
url: url,
type: 'post',
contentType: 'application/json',
dataType: 'json',
data: JSON.stringify(send_data)
}).always(function (response) {
console.log(' response: ', response);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.