0

以下のコードを使用して、ページをリロードせずにフォームを送信しますが、AJAX の成功部分で data.a="a"、または "b" などの場合でも、従来どおりにフォームを送信したいと思います。 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

すでに述べたように、内部で別の ajax 呼び出しを行うことができます

コメントの後の版、:

これを試して...

<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 に答える