为什么这个卷曲请求不起作用

时间:2018-02-01 14:38:35

标签: php curl getresponse

我想通过ajax发送订阅表单。脚本返回200,但GetResponse列表中没有任何反应。有谁知道?非常感谢您的帮助。

$email = $_POST['email'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$custom_field = $_POST['custom_field'];
$params = array(
    'email' => $email,
    'campaign_token'=>'xxx',
    'first_name' => $name,
    'last_name' => $last_name,
    'custom_field' => $custom_field
);
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL , 'https://app.getresponse.com/add_subscriber.html');
curl_setopt($ch, CURLOPT_POST , true);
curl_setopt($ch, CURLOPT_POSTFIELDS , $params);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$server_output = curl_exec ($ch);

curl_close ($ch);
echo 'ok';

//编辑这是验证和发送表单的jquery脚本。抱歉。我没想到它可能是nesesery。

$(document).ready(function(){
    function isValidEmailAddress(emailAddress) {
        var pattern = /^([a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+(\.[a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+)*|"((([ \t]*\r\n)?[ \t]+)?([\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*(([ \t]*\r\n)?[ \t]+)?")@(([a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.)+([a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.?$/i;
        return pattern.test(emailAddress);
    };
    var label = $('#error');
    $('#sub-input').submit(function(e){
    e.preventDefault();
    var url = $(this).attr('action');
    var emailaddress = $(this).find('input[name=email]').val();
    if(emailaddress == ''){
         label.text('input email').css({'color':'red'});
        return false;
    }

    if( !isValidEmailAddress( emailaddress ) ) { 
    label.text('error').css({'color':'red'});
        return false;
    }
        var data = $(this).serialize();

        $.ajax({
            url: "https://aexample.com/sub.php", <--adress of this curl above
            type: "POST",
            data: data,
            success: function(response, textStatus, xhr){
                console.log(xhr.status);
                if(xhr.status){
                    label.text('Successfully subscribed ').css({'color':'green'});

                }

            }
        });
    });
});

0 个答案:

没有答案