3

フォームが正常に完了した後、ユーザーをサンキュー ページにリダイレクトする際に問題が発生しています。何が起こるかというと、フォームが送信された後、空白のページ ( https://cunet.sparkroom.com/Sparkroom/postLead ) に移動します...フォームの詳細を「フォーム アクション」の URL。

HTML コード:

<form action="https://cunet.sparkroom.com/Sparkroom/postLead/" method="post" name="theForm" 
id="theForm" onSubmit="return MM_validateForm();" >
...
</form>

Ajax コード:

<script src="http://malsup.github.com/jquery.form.js"></script> 
<script> 
    $('#theForm').ajaxForm(function() { 
    window.location.href = "I want the user to be redirected to this page";
});
</script> 

JavaScript:

function MM_validateForm() {
if ( !jQuery('#theForm #FirstName').val() ) {
alert('Please input your first name.');
jQuery('#theForm #FirstName').focus();
return false;
}
if ( !jQuery('#theForm #LastName').val() ) {
alert('Please input your last name.');
jQuery('#theForm #LastName').focus();
return false;
}
if ( !jQuery('#theForm #daytimephone').val() ) {
alert('Please input your phone number.');
jQuery('#theForm #daytimephone').focus();
return false;
}
if ( !jQuery('#theForm #Email').val() ) {
alert('Please input your email.');
jQuery('#theForm #Email').focus();
return false;
}
if ( !jQuery('#theForm #BID').val() ) {
alert('Please select your preferred campus.');
jQuery('#theForm #BID').focus();
return false;
}
if ( !jQuery('#theForm #programs').val() ) {
alert('Please select your preferred program.');
jQuery('#theForm #programs').focus();
return false;
}
if ( !jQuery('#theForm #How_Heard').val() ) {
alert('Please select how you heard about us.');
jQuery('#theForm #How_Heard').focus();
return false;
}
return true;
}
// ]]></script>

私が間違っていることを誰かが知っていますか?データを URL に送信するためのフォームが必要であり、ユーザーを「ありがとう」ページにリダイレクトした後、現在はまったく発生していません。

4

4 に答える 4

4

試す

window.location.href = "http://www.msdn.com";
于 2013-07-19T14:55:34.983 に答える
3

試す:

$('#theForm').ajaxForm(function() { 
 success : function(){
    window.location.href = "Url to redirect here in the success option";
 }
});
于 2013-07-19T14:54:13.187 に答える
0

jquery を使用して投稿を送信することができるため、フォームでアクションをキャンセルする必要があります。

    <form  name="theForm" id="theForm" >

送信ボタンにクラスまたは ID を指定するだけです

    <submit class='submitTheForm'....>

コードは次のようになります。すべてのフォーム変数を正しい名前で含める必要があります。

次に、MM_validateForm() の下部に jquery ポスト リクエストを追加します。

    if ( !jQuery('#theForm #How_Heard').val() ) {
    alert('Please select how you heard about us.');
    jQuery('#theForm #How_Heard').focus();
    return false;
    }

    $.post("https://cunet.sparkroom.com/Sparkroom/postLead/",
{
FirstName:FirstName,
LastName:LastName
    ...
    ...
},
function(){
    window.location.href = 'thank you page'
    }
});

最後に、送信ボタンがクリックされたときに関数 MM_validateForm() を呼び出します

    $('.submitTheForm').click( function(){
    MM_validateForm();
    });

http://api.jquery.com/jQuery.post/からの jquery の投稿残りは個人的な経験から。

于 2013-07-19T15:19:04.557 に答える