Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 调试ajax时遇到问题_Jquery_Ajax_Wordpress_Infusionsoft - Fatal编程技术网

Jquery 调试ajax时遇到问题

Jquery 调试ajax时遇到问题,jquery,ajax,wordpress,infusionsoft,Jquery,Ajax,Wordpress,Infusionsoft,我在调试ajax请求时遇到了很多问题。相同的调用在同一服务器上的旧版本站点上运行良好。这是一段将数据从Wordpress发送到Infusionsoft的代码。我检查过了,一切正常。我还安装了一个CORS headers插件,认为这可能是问题所在,但显然不是。通过以下操作,我得到了一个解析错误: var r=confirm("Are you sure you wish to create the '" + profile.title + "' email template?"); if

我在调试ajax请求时遇到了很多问题。相同的调用在同一服务器上的旧版本站点上运行良好。这是一段将数据从Wordpress发送到Infusionsoft的代码。我检查过了,一切正常。我还安装了一个CORS headers插件,认为这可能是问题所在,但显然不是。通过以下操作,我得到了一个解析错误:

  var r=confirm("Are you sure you wish to create the '" + profile.title + "' email template?");
    if (r==true) {
        $('#mailout_buttons').hide();
        $('#mailout_progress').show();
        var request = $.ajax({
            type : "post",
            dataType : "jsonp",
            url : ajaxurl,
            data : $.extend(profile, {action: "create_weekly_email"}),
            xhrFields: {
                withCredentials: true
            },
            error: function(XHR, textStatus, errorThrown)
            {       
                alert(textStatus);                                 
            },
            success: function(response) {
                if(response.type == "success") {
                    $('#mailout_buttons').show();
                    $('#mailout_progress').hide();
                    $('#mailout_success').show();
                }
                else {
                    alert("Error with template creation")
                }
            }
        });
        request.done(function(msg){ console.log(msg)});
        request.fail(function(jqXHR, textStatus){ console.log("Request failed: " + textStatus)});
如果我将错误改为:

            error: function(e)
            {       
                alert(JSON.stringify(e), null, 4);                                 
            },
我得到:

{“readyState”:4,“responseText”:“创建{\”类型\“:\”成功\“}”,“状态”:200,“状态文本”:“确定”}

我也尝试过用文本和html发布。使用html,它告诉我JSON的格式不好,尽管使用,它说是。通过使用文本,它将转到成功回调中的else

编辑1: 我在下面发布了创建每周电子邮件功能。create_weekly_email调用get_weekly_email,其中包含sql查询。我在其中硬编码了几个变量,返回的结果是phpmyadmin和responseText变量。我可以看到返回了一些格式错误的html(它创建了一个office文档),html的长度各不相同。我不想在这里发布返回的数据,但在最后一次调用中,它丢失了所有的结束标记。有时返回的字符串要短得多,这使我认为可能存在某种超时问题

function create_weekly_email() {

    if(empty($_SERVER['HTTP_X_REQUESTED_WITH']) || strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') {
        header("Location: " . $_SERVER["HTTP_REFERER"]);
        exit;
    }


    $result = ["type" => "error"];
    if($profile = filter_input_array(INPUT_POST, massemail_fields())) {
        if($re = create_weekly_mail_template($profile)) {
            $result = ["type" => "success"];
        }
    }
    wp_send_json($result);
    exit;
}
试试这个脚本

只需将此
数据类型:“jsonp”
替换为
数据类型:“json”


你能从tuntions.php发布你的
create\u weekly\u email
功能吗?谢谢你让我走上正轨。我已经用一个editno更新了这个问题,我已经设法调试它,直到请求与数据一起发送。据我所知,这是php中echo/prints与一些不正确路径的组合。谢谢你抽出时间。
var r=confirm("Are you sure you wish to create the '" + profile.title + "' email template?");
if (r==true) {
    $('#mailout_buttons').hide();
    $('#mailout_progress').show();
    var request = $.ajax({
        type : "post",
        dataType : "json",
        url : ajaxurl,
        data : $.extend(profile, {action: "create_weekly_email"}),
        xhrFields: {
            withCredentials: true
        },
        error: function(XHR, textStatus, errorThrown)
        {       
            alert(textStatus);                                 
        },
        success: function(response) {
            if(response.type == "success") {
                $('#mailout_buttons').show();
                $('#mailout_progress').hide();
                $('#mailout_success').show();
            }
            else {
                alert("Error with template creation")
            }
        }
    });
    request.done(function(msg){ console.log(msg)});
    request.fail(function(jqXHR, textStatus){ console.log("Request failed: " + textStatus)});