0

我使用下面的代码在不重新加载页面的情况下提交我的表单,但是当 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;
});
4

2 回答 2

2

正如已经说过的,您可以在

评论后的版本,:

试试这个...

<form id="inscription_form_home" action="index.php?module=membres&action=inscription" 

    method="post" >
    ...
    <button id="mButton">Submot<button>
    </form> 


$(document).ready(function() {$("#mButton").bind('click', mysubmit($));});

   function mysubmit()
   {    
    $.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" ){
                //do your new call here, or you can also submit the form
            }else{                  
                alert("Inscription OK.");
            }
        }
    });    
    return false;
    }
于 2012-10-30T19:17:52.583 回答
0

你可以这样:

$(location).attr('href',YOUR URL);
于 2012-10-30T16:09:50.600 回答