我使用下面的代码在不重新加载页面的情况下提交我的表单,但是当 data.a="a" 或 "b" 等在 AJAX 的成功部分时,我仍然想按照传统方式提交表单没有jQuery的php。
所以在这种情况下,目的是将 AJAX 数据(“data:myForm.serialize()+”&id_town="+id_town,")传输到表单的“action”html 属性中指定的 url。
你有什么主意吗 ?
html代码:
<form id="inscription_form_home" action="index.php?module=membres&action=inscription" method="post" >
...
</form>
jQuery代码:
$("#inscription_form_home").submit(function() {
var myForm = $(this);
$.ajax({
dataType: 'json',
type: "POST",
url: "traitement_profil.php",
data:myForm.serialize()+"&id_town="+id_town,
success: function(data){
if (data.a == "a" || data.a == "b" ){
// Transmit the data part to the form url
}else{
alert("Inscription OK.");
}
}
});
return false;
});