[英]Ajax with wordpress, 400 bad request
I try to submit a form using Ajax, working in a plugin.我尝试使用 Ajax 提交表单,在插件中工作。 I developed two plugins the first one was working but not anymore and I didn't find any mistakes.
我开发了两个插件,第一个正在工作但不再工作,我没有发现任何错误。 I think that is not coming from the code it self but I'm a bit lost.
我认为这不是来自代码本身,但我有点迷茫。
Here is my php :这是我的 php :
wp_enqueue_script( 'b_form', plugin_dir_url( __FILE__ ) . 'js/b-form.js', array( 'jquery') );
wp_localize_script( 'b_form', 'ajax_url', admin_url( 'admin-ajax.php' ) );
include plugin_dir_path( __FILE__ ) . 'pages/b-form.php';
and my js :和我的 js :
var fd = new FormData( document.getElementById( 'b_form' ) );
fd.append( 'action', 'b_generate_comparison' );
$.ajax({
type: "POST",
url: ajax_url,
data: fd,
contentType: false,
processData: false,
})
.done( function( response ) {
...
}
.fail( function( response ) {
...
}
.always( function( response ) {
...
}
Try below code and if it couldn't work then check following things - Change URL in below code -尝试下面的代码,如果它无法工作,请检查以下内容 - 在下面的代码中更改 URL -
var fd = new FormData( document.getElementById( 'b_form' ) );
fd.append( 'action', 'b_generate_comparison' );
$.ajax({
type : 'POST',
url : 'http://YOUR_SITE_URL/wp-admin/admin-ajax.php',
dataType : 'json',
data: fd,
contentType: false,
processData: false,
success : function( response ) {
.done( function( response ) {
...
}
.fail( function( response ) {
...
}
.always( function( response ) {
...
}
} // success
}); // Ajax request end
Checklist清单
Hope this could help.希望这会有所帮助。 Happy Coding.
快乐编码。
I was posting files and there were to big,我正在发布文件,而且文件很大,
So in /etc/php/7.0/apache2/php.ini
increase于是在
/etc/php/7.0/apache2/php.ini
增加
upload_max_filesize = 13M
post_max_size = 27M
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.