0

icontact で Ajax を使用しようとしています。コードはフォームを送信しますが、フォームが機能し、詳細がリストにドロップされているにもかかわらず、エラー メッセージが表示されます。

$('.error').hide();
$('.erroremail').hide();
$('#successcontainer').hide();
function verifyRequired()
{ 
    var eReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/; // regex to check valid email
    var email = $('input[name="fields_email"]').val();
    var name = $('input[name="fields_fname"]').val();
    var phone = $('input[name="fields_phone"]').val();
    var data = $("#form-popup").serialize()

    if (email == "") {
        $('input[name="fields_email"]').focus();
        $('.error').show();
        return false;
    } else if (!eReg.test(email)) {
        $('input[name="fields_email"]').focus();
        $('.erroremail').show();
        return false;
    }
    else if (name == "") {
        $('input[name="fields_name"]').focus();
        $('.error').show();
        return false;
    }
    else if (phone == "") {
        $('input[name="fields_phone"]').focus();
        $('.error').show();
        return false;
    }
    else {
        $.ajax({
            url: "https://app.icontact.com/icp/signup.php", 
            type: "POST",
            data: data,
            success: function(){
                alert('success')
            },
            error: function(){
                alert('failure')
            },
        });
        return false;
    }
}

フォームは詳細を送信していますが、失敗メッセージが表示されていますか?

だから私はほとんどそこにいます、誰かが理由を知っていますか?

乾杯

フォームもこちら

<form id="form-popup" method="post" action="" name="icpsignup" accept-charset="UTF-8" onsubmit="return verifyRequired();" >
    <input type="hidden" name="redirect" value="http://www.icontact.com/www/signup/thanks.html">
    <input type="hidden" name="errorredirect" value="http://www.icontact.com/www/signup/error.html">
    <input type="text" name="fields_fname" class="input" id="name" placeholder="Full Name" />
    <input type="text" name="fields_email" class="input" id="email" placeholder="Email Address" />
    <input type="text" name="fields_phone" class="input" id="phone" placeholder="Telephone" />
    <input type="submit" id="submit" />

    <input type="hidden" name="listid" value="xxxxxxx">
    <input type="hidden" name="specialid:xxxxx" value="xxxx">
    <input type="hidden" name="clientid" value="xxxxxx">
    <input type="hidden" name="formid" value="xxxx">
    <input type="hidden" name="reallistid" value="1">
    <input type="hidden" name="doubleopt" value="0">
</form>
4

1 に答える 1

0

あなたのコードをローカル サーバーで実行しましたが、構文エラーは見つかりませんでした。

あなたのコードを使用する際に直面する問題は、「Cross-Origin Request Blocked」です。

ブラウザは、別のドメインへの AJAX リクエストを許可しません。サイト app.icontact.com (またはおそらく icontact.com) でフォームを使用しようとすると、機能します。

フォームに icontact.com を使用できない場合は、処理する PHP コード (この場合はサーバー側の言語) を作成することをお勧めしますjsonp。これはクロスオリジン ポリシーの回避策です。

dataType:jsonpを追加$.ajax

$.ajax({
    url: "https://app.icontact.com/icp/signup.php", 
    type: "POST",
    dataType: "jsonp",
    data: data,
    success: function(){
        alert('success')
    },
    error: function(){
        alert('failure')
    },
})

上記のコードを実行すると、signup.php から構文エラーが発生したため、jsonp を正しく処理すると、成功のアラートが表示されると思います。

于 2014-07-07T21:04:27.660 に答える