Jquery POST 500内部错误]在尝试提交Wufoo表单时

时间:2012-10-31 16:05:09

标签: ajax post wufoo

我试图通过AJAX提交一个wufoo表单。我使用jQuery $ .post来实现这一点,并从php脚本返回500(内部服务器错误)。 javascript代码是:

$('form#form20').submit(function(event){
    event.preventDefault();
    $.post('form_handler.php', $('form#form20').serialize(), function(response) {
        console.log(response);
    });
});

form_handler.php文件中的php代码是:

<?php  
    if (count($_POST) > 0) {
        $fieldErrors = initAPI($root);
    }
    $wufoo_query_vals = array(
        'w_api_key' => 'xxxx-xxxx-xxxx-xxxx',
        'w_form' => 'connect-with-us',
        '1' => $_POST['Field1'],
        '2' => $_POST['Field2'],
        '3' => $_POST['Field3'],
        '4' => $_POST['Field4'],
        '5' => $_POST['Field5'],
        '11' => $_POST['Field11'],
        '14' => $_POST['Field14'],
        '13' => $_POST['Field13'],
        '8' => $_POST['Field8'],
        '9' => $_POST['Field9']
    );

    foreach($wufoo_query_vals as $key => $value) {
        $request .= $key.'='.urlencode($value).'&';
    }
    $request = substr($request, 0, -1);
    $ch = curl_init("http://defineyouredge.wufoo.com/api/insert/"); 
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
    $response = curl_exec($ch);
    curl_close ($ch);

    echo $response;  
?>

我已经删除了API密钥,原因很明显,但我确实在实际代码中输入了它。此外,我还没有完成处理响应的功能。目前,只需将响应记录到控制台进行测试。

非常感谢您的支持!

0 个答案:

没有答案