php400错误的请求,Wordpress中的Ajax返回400错误请求,但不确定如何进一步调试 - WordPress - srcmini...
我一直试图使用Ajax将页面的数据(或其他任何东西)输出到div中。数据基于页面上的列表。尽管调用Ajax请求的jQuery函数似乎可以正常工作, 但是从Ajax调用在控制台上却收到了400个错误的请求。如何调试它, 因为我无法从Ajax回调函数中获取任何console.log消息
我有一个wordpress文件, 该文件输出产品类别的列表以及单击列出的类别之一时触发的一些jQuery。该jQuery具有Ajax发布函数来调用我的入队和本地化函数。该函数似乎没有任何作用, 即使是简单的console.log, ajax调用的:error也表明该错误是一个400错误的请求。使用WPEngine密码保护的登台站点, 可能会有所作为。
in functions.php
--------------------
--------------------
in funcitons.php
--------------------
// for displaying products in div on category page
function enqueue_show_products_scripts () {
// get the javascript file and enqueue it, then ad it to the wp_print_scripts action
$script_location = get_stylesheet_directory_uri() . "/includes/js/show_products.js";
wp_enqueue_script( 'ajax-script', $script_location, array ('jquery') );
wp_localize_script( 'ajax-script', 'ajax', array('url' => admin_url( 'admin-ajax.php' )) );
}
add_action ('wp_print_scripts', 'enqueue_show_products_scripts');
// this is the function that the Ajax request is running
function show_products_callback() {
// Get the request dataglobal $wpdb;
?>
console.log ("in show_products_callback");
// get_the_data
//echo(get_term_link($_POST['term_id']));
//get_term_link($_POST['term_id']);
//get_term_link(680);
//print_r($_REQUEST);
die();
}
// and this adds the actions on init to register the function with the Ajax and
add_action ( 'wp_ajax_nopriv_show_products', 'show_products_callback' );
add_action ( 'wp_ajax_show_products', 'show_products_callback' );
in show_product.js
----------------------
jQuery(document).ready( function() {
jQuery('#categoryListBox a').click ( function () {
var term_id_clicked = jQuery(this).attr('id');
alert ("Clicked " + term_id_clicked );
jQuery.post ( {
url: ajax.url, action: 'show_products', term_id: term_id_clicked, success: function ( data ) {
console.log (data), jQuery('#productBox').html(data)
}, error: function (errorThrown) {
console.log ("errorThrown"), console.log (errorThrown)
}
}
); // end jQuery.ajax
}); // end jQuery click
});
jQuery( document ).ajaxError(function( event, data, settings, exception ) {
alert( "Triggered ajaxError handler." +event+" "+data+" "+settings+" "+exception);
});
in show_all_products_by_category.php
---------------------------------
All products by Category
...
$child_product_cats = get_terms( $child_args );
foreach ($child_product_cats as $child_product_cat)
{
$name = $child_product_cat->name;
$slug = $child_product_cat->slug;
$term_id = $child_product_cat->term_id;
?>
= $child_product_cat->name?>
// the id is the slug of the subcategory, and the action is performed in the jQuery event
} // end FOREACH CHILD
?>
...
I keep getting error 400 bad request in the console, but am stumped on how to further debug, as no output from the callback function appears when I echo, alert or console.log.
项目清单
in show_product.js
----------------------
jQuery(document).ready( function() {
jQuery('#categoryListBox a').click ( function () {
var term_id_clicked = jQuery(this).attr('id');
alert ("Clicked " + term_id_clicked );
jQuery.post ( {
url: ajax.url, action: 'show_products', term_id: term_id_clicked, success: function ( data ) {
console.log (data), jQuery('#productBox').html(data)
}, error: function (errorThrown) {
console.log ("errorThrown"), console.log (errorThrown)
}
}
); // end jQuery.ajax
}); // end jQuery click
});
jQuery( document ).ajaxError(function( event, data, settings, exception ) {
alert( "Triggered ajaxError handler." +event+" "+data+" "+settings+" "+exception);
});
in show_all_products_by_category.php
---------------------------------
All products by Category
...
$child_product_cats = get_terms( $child_args );
foreach ($child_product_cats as $child_product_cat)
{
$name = $child_product_cat->name;
$slug = $child_product_cat->slug;
$term_id = $child_product_cat->term_id;
?>
= $child_product_cat->name?>
// the id is the slug of the subcategory, and the action is performed in the jQuery event
} // end FOREACH CHILD
?>
...
我一直在控制台中收到错误400错误的错误请求, 但在如何进一步调试方面感到困惑, 因为当我回声, 警报或console.log时, 没有出现回调函数的输出。
#1
只是想通了。
我对jQuery.post进行了如下代码更改:原始-无法正常工作:
jQuery.post({url:ajax.url, action:’show_products’, term_id:term_id_clicked, success:function(data){
转换为这种格式, 现在返回200代码:
jQuery.post ( {
url: ajax.url, data : {
action : 'show_products', term_id : term_id_clicked
}, success: function ( data ) {
顺便说一句, 联系了WPEngine, 即使该站点处于”可转让”模式(需要用户名和密码), 这也不是问题。
php400错误的请求,Wordpress中的Ajax返回400错误请求,但不确定如何进一步调试 - WordPress - srcmini...相关推荐
- https返回400_HTTP请求中带有特殊字符|,返回400错误
Java平台,服务器是Tomcat8,前端ajax访问服务器时,F12返回400错误,经分析,URL地址中get传参值里面含有"|", Invalid character foun ...
- 如何修复WordPress中的504网关超时错误
你有没有在你的WordPress网站上出现过504网关超时错误?此错误可能会使用户无法访问您的网站.最糟糕的是,如果根本问题没有解决,它可以自行消失并重新出现.在本文中,我们将向您展示如何修复Word ...
- wordpress api ajax,Woocommerce rest api - 在wordpress中通过ajax创建产品
嗯,问题在这里.我创建了一个本地项目,用于在远程服务器上的wordpress中安装Woocommerce中的产品.我的本地项目的代码是这样一个Woocommerce rest api - 在wordp ...
- PostMan发送请求参数带有路径特殊字符会返回400错误(与URL字符及URL编码值有关)
目录 一.请求参数中携带URL字符返回400错误 二. 请求参数中携带URL字符返回400错误原因 三.URL字符及对应的URL编码值列表 四.请求参数中携带URL字符转成URL编码值 一.请求参数中 ...
- sweetalert 2.0 ajax,处理SweetAlert2中的AJAX返回值
我使用带有AJAX请求的SweetAlert2 Popup.一旦用户点击提交,我执行请求. 在PHP文件中,我对提交的数据进行了一些验证,根据结果,我想在SweetAlert2中为用户提供反馈作为信息 ...
- layer中html字符转换,在layer弹出层中通过ajax返回html拼接字符串填充数据的方法...
1,在给一个layer弹出层做checkbox自动选中时,ViewBag传递的时object类型,用不了lambda表达式,代码如下, @foreach (var perm in ViewBag.al ...
- 客户端返回400错误
今天测试终端连接服务器,返回400错误,定位了一下,是终端post请求问题.我们post的数据是json格式的,但是Content-Type却是application/x-www-form-urlen ...
- Geoserver禁止返回400错误
使用Geoserver的瓦片服务时,比如wmts服务,如果不再范围内就会返回400错误,内容是text/xml格式,是一些瓦片行列号不在范围内的信息. 对于大范围内的瓦片我们可以不用关心这类问 ...
- 【WebApi】WebApi的Post方法的参数问题和C#调用WebApi返回400错误
学习WebApi时间较短,在一个项目中需要向WebApi发送数据,但是使用C#调用WebApi(Post)时总返回400错误,找了很久,总以为是调用方法有问题,后来发现其实是WebApi中,Post方 ...
最新文章
- opencv中的CommandLineParser类用法
- postgresql中自定义函数脚本的备份及恢复
- caffe使用过程+digits在windows下的安装和运行
- 如何在ngRepeat中使用Bootstrap Span元素
- c++中sort()的用法
- C++ std::move/std::forward/完美转发
- Scapy 函数传值问题,解决多层数据获取
- 计算机专业必懂知识,学习计算机知识必须懂得50个专业术语
- ppt取色html,ppt如何使用取色器? ppt取色器的使用方法
- 然并卵却很拉风!360超级充电器评测_天极网
- linux vi 表格,关于Linux vi命令 vi命令一览表
- 基于Java的NetCDF文件解析
- 查询最近三个月的数据
- Windows Shell编程-第十章.Winows辅助库
- 如何修改Android应用程序的图标和名字
- 处理办公文档通过共享打印机无法打印
- android p 荣耀v10,荣耀V10和V9哪个好 区别对比分析告诉你
- 旷视2022:以产品之能加速行业发展,以生态之力开拓AIoT蓝海
- 《企业管理学》——组织与组织文化(企业文化)知识点总结
- 论文阅读:Visual Relationship Detection with Language Priors
热门文章
- java转置矩阵相乘_java实现矩阵的加-减-乘-转置运算
- idl结果显示窗口如何缩小_IDL操作步骤
- 通过sessionid获取session php,php如何返回sessionID和如何通过sessionID获取相关的session...
- 数据科学工具 Jupyter Notebook 教程(二)
- 王二涛团队及合作者揭示沙棘放线菌固氮生物学机制
- ​北京大学吴华君组诚聘医学/生信助理研究员和博士后
- PCE:南农张瑞福组揭示微生物肥料菌种芽孢杆菌应对植物免疫防卫实现根际定殖的新策略...
- Nature:复杂菌群空间分布研究
- WIRW:淡水分子微生物生态学综述
- 50个ggplot2可视化案例