Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/284.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/jquery/71.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
Php 400错误请求-使用Jquery和Wordpress的Ajax_Php_Jquery_Ajax_Wordpress - Fatal编程技术网

Php 400错误请求-使用Jquery和Wordpress的Ajax

Php 400错误请求-使用Jquery和Wordpress的Ajax,php,jquery,ajax,wordpress,Php,Jquery,Ajax,Wordpress,我ḿ 尝试在JQuery脚本中使用ajax将JQuery变量读入Wordpress的functions.php $.ajax({ url: js_admin_url.ajax_url, type: 'POST', beforeSend: function(xhr) { xhr.setRequestHeader("Authorization", "CloudSight [key

我ḿ 尝试在JQuery脚本中使用ajax将JQuery变量读入Wordpress的functions.php

$.ajax({

    url: js_admin_url.ajax_url,
                  type: 'POST',
                  beforeSend: function(xhr) {
                    xhr.setRequestHeader("Authorization", "CloudSight [key]");
                  },
                  data: JSON.stringify({
                      'action': 'send_ranking_data', // Ação do Ajax
                      '_ajax_nonce': js_admin_url.nonce,
                      's': settings.ranking // O que vamos postar para $_POST
                  }),
                  dataType: "json",
                  contentType: "application/json",
                  success: function(response) { console.log(response); },
                  error: function(e) { console.log(e); }
              });


状态代码:400错误请求

我至少知道您不应该使用JSON.stringify处理ajax数据,只需执行以下操作:

data: {
    'action': 'send_ranking_data',
    '_ajax_nonce': js_admin_url.nonce,
    's': settings.ranking
}
这将自动以JSON的形式发送数据