Php 卷曲形反应

Php 卷曲形反应,php,jquery,curl,Php,Jquery,Curl,我的表格有问题。问题是,当单击submit时,jQuery在response.length>0语句中不起作用,但是表单正在工作并导入数据,但我需要它更新div并加载感谢页面,而不是像什么都不做一样:) 它应该是response.length>0-然后加载错误并更新div否则转到感谢页面 jQuery: $('#mountianForm').submit(function(e) { // catch the form's submit event $.ajax({ // crea

我的表格有问题。问题是,当单击submit时,jQuery在
response.length>0
语句中不起作用,但是表单正在工作并导入数据,但我需要它更新div并加载感谢页面,而不是像什么都不做一样:)

它应该是
response.length>0
-然后加载错误并更新div
否则
转到感谢页面

jQuery:

 $('#mountianForm').submit(function(e) { // catch the form's submit event
        $.ajax({ // create an AJAX call...
            data: $(this).serialize(), // get the form data
            type: $(this).attr('method'), // GET or POST
            url: $(this).attr('action'), // the file to call
            success: function(response) { // on success..
                if (response.length > 0) {
                        $('#mountianFormResponse').html(response); // update the DIV
                } else {
                           window.location.href = 'https://example.com/thank-you/';               

                }
            }
        });
        e.preventDefault();
    });
<?php

error_reporting(E_ALL); ini_set('display_errors', 1);


$url = 'https://id.infusionsoft.com/app/form/iframe/formID';
$userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36';

if (!empty($_GET))
{
    $url .= '?'.http_build_query($_GET);
}

$isPOST = !empty($_POST);


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_POST, $isPOST);
if ($isPOST)
{
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($_POST));
}
$response = curl_exec($ch);
curl_close($ch);

if(preg_match('/(<ul>.*<\/ul>)/is', $response, $match)){
    $match[1];
}else{
$error = "Error";    
$file = fopen("mountianProxyerror.php", 'w+'); // Create a new file, or overwrite the existing one.
fwrite($file, $error);
fclose($file);

}

?>
过程代码:

 $('#mountianForm').submit(function(e) { // catch the form's submit event
        $.ajax({ // create an AJAX call...
            data: $(this).serialize(), // get the form data
            type: $(this).attr('method'), // GET or POST
            url: $(this).attr('action'), // the file to call
            success: function(response) { // on success..
                if (response.length > 0) {
                        $('#mountianFormResponse').html(response); // update the DIV
                } else {
                           window.location.href = 'https://example.com/thank-you/';               

                }
            }
        });
        e.preventDefault();
    });
<?php

error_reporting(E_ALL); ini_set('display_errors', 1);


$url = 'https://id.infusionsoft.com/app/form/iframe/formID';
$userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36';

if (!empty($_GET))
{
    $url .= '?'.http_build_query($_GET);
}

$isPOST = !empty($_POST);


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_POST, $isPOST);
if ($isPOST)
{
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($_POST));
}
$response = curl_exec($ch);
curl_close($ch);

if(preg_match('/(<ul>.*<\/ul>)/is', $response, $match)){
    $match[1];
}else{
$error = "Error";    
$file = fopen("mountianProxyerror.php", 'w+'); // Create a new file, or overwrite the existing one.
fwrite($file, $error);
fclose($file);

}

?>

我认为您没有从流程代码返回响应。

if(preg_match('/(<ul>.*<\/ul>)/is', $response, $match))
{
    $match[1];
    $resp = array('status' => TRUE,'msg' => 'success','resp' => $response);
}
else
{
    $error = "Error";    
    $file = fopen("mountianProxyerror.php", 'w+'); // Create a new file, or overwrite the existing one.
    fwrite($file, $error);
    fclose($file);
    $resp = array('status' => FALSE,'msg' => 'Failed');
}

echo json_encode($resp);

在ControllerTry中显示的json_编码行上显示一个
未定义变量resp
错误,添加额外的行->
$resp=array('status'=>FALSE,'msg'=>'Failed')如果(preg_match('/(
    *)/is',$response,$match))
这行告诉我发生了什么