提交表单时不刷新页面便无法读取数据库。可以只使用php直接返回。但是无法从数据库中读取。我在这个话题上搜索了很多。但是我找不到解决方案。作为初学者,我需要这里所有专家的帮助。
这是js代码:
$(document).ready(function(){
$("#createGuestForm").submit(function(event){
submitForm();
return false;
});
});
function submitForm(){
$.ajax({
type: "POST",
url: "individual_orders.php",
cache:false,
data: $('form#createGuestForm').serialize(),
success: function(response){
$("#myAjax_one").html(response)
$("#indivi_modal1").modal('show')
$("#createGuestForm")[0].reset();
},
error: function(){
alert("Error");
}
});
}
<form method="post" id = "createGuestForm" role="form">
<div class="modal-body">
<div class="alert alert-success result" id="myAjax_one"></div>
<div class="form-inline">
<input type="text" name="name" id="fname" tabindex="1" class="form-control my-1 mr-sm-1"
placeholder="name" value="" required>
<input type="phone" name="phone" id="phone" tabindex="1" class="form-control my-1 mr-sm-1"
placeholder="TEL: 87772228844" value="" required>
</div>
<div class="form-inline">
<input type="text" name="username" id="username" tabindex="1" class="form-control my-2 mr-sm-1"
placeholder="Login-id" value="" readonly>
<label for="cityFormControlSelect1"></label>
<select class="form-control form-control my-2 mr-sm-1" id="cityFormControlSelect1" name="city" required>
<option selected hidden value="">city...</option>
<option value="1">city1</option>
</select>
</div>
<hr>
<div class="form-group">
<input type="email" name="email" id="register_email2" tabindex="3"
class="form-control" placeholder="Email" value="">
</div>
<div class="form-group">
<input type="address" name="address" id="Address" tabindex="3"
class="form-control" placeholder="Мекен-жайы (Міндетті емес)" value="">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary" name="register-submit" id="indi_save_btn1" form="createGuestForm">Save</button>
</div>
</form>
您的jQuery代码有错误,请先更正。
function submitForm(){
$.ajax({
type: "POST",
url: "individual_orders.php", //You have missed quates here....
cache:false,
data: $('form#createGuestForm').serialize(),
success: function(response){
$("#myAjax_one").html(response)
$("#indivi_modal1").modal('show')
$("#createGuestForm")[0].reset();
},
error: function(){
alert("Error");
}
});
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句