提交表格两次Javascript

时间:2015-04-30 06:25:02

标签: javascript jquery html forms

我正在尝试两次提交表单。我需要执行javascript方法然后执行表单本身。首先发布到http://spotplatform.growbinary.com/openAccount/wpRegister,然后发布到http://www.growbinary.com/。如果错误存在,请停止提交。谢谢

<form id="open-account-form" name="open-account-form" method="post" action="http://www.growbinary.com/">
    <button type="submit" name="submit" class="open-account-form-input submit">Claim Your $30 Bonus</button>
</form>

我有这个JavaScript功能。

$('#open-account-form').submit(function () {
    var first_name = $.trim($('#open-account-form-first-name').val());
    var last_name = $.trim($('#open-account-form-last-name').val());
    var email = $.trim($('#open-account-form-email').val());
    var country = $('#open-account-form-country').val();
    var phone_prefix = '1';
    var phone_area = '1';
    var phone_number = '1';
    var errors = '';
    if (!(first_name.length > 0)) {
        errors += "Please Enter Your First Name." + "\n\n";
    }
    if (!(last_name.length > 0)) {
        errors += "Please Enter Your Last Name." + "\n\n";
    }
    if (!(email.length > 0)) {
        errors += "Please Enter Your Email Address." + "\n\n";
    }
    if (!(country > 0)) {
        errors += "Please Select Your Country." + "\n\n";
    }
    if (!(phone_prefix.length > 0)) {
        errors += " Please Enter Your Phone Prefix." + "\n\n";
    }
    if (!(phone_area.length > 0)) {
        errors += "Please Enter Your Phone Area." + "\n\n";
    }
    if (!(phone_number.length > 0)) {
        errors += "Please Enter Your Phone Number." + "\n\n";
    }
    if (errors.length > 0) {
        alert(errors);
    } else {
        var data_object = {
            "FirstName": first_name,
            "LastName": last_name,
            "email": email,
            "Country": country,
            "Prefix": phone_prefix,
            "Area": phone_area,
            "Phone": phone_number,
            "campaignId": $.cookie('campaignId'),
            "subCampaign": $.cookie('subCampaignId'),
            "specialNeedHelp": 1,
            "registerAsLead": 1,
            "returnPixel": true
        };
        $.ajax({
            url: "http://spotplatform.growbinary.com/openAccount/wpRegister",
            type: "POST",
            data: data_object,
            success: function (data) {
                var response = eval("(" + data + ")");
                if ((response.status === true) && (response.result === "leadCreated")) {
                    alert("I am here");
                    if (errors.length > 0) {
                        alert("erros");
                        $('#open-account-form').submit(formValidated);
                    }
                }
                if (errors.length > 0) {
                        alert(errors);
                    }
                }
            }
        });
    }
});

0 个答案:

没有答案
相关问题