Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/239.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/cmake/2.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
邮递http://localhost/website/wp-admin/admin-ajax.php 400(错误请求)_Php_Ajax_Wordpress_Customization_Custom Wordpress Pages - Fatal编程技术网

邮递http://localhost/website/wp-admin/admin-ajax.php 400(错误请求)

邮递http://localhost/website/wp-admin/admin-ajax.php 400(错误请求),php,ajax,wordpress,customization,custom-wordpress-pages,Php,Ajax,Wordpress,Customization,Custom Wordpress Pages,我需要从用户那里获取图像输入,并使用AJAX将其保存到WordPress网站数据库中,无需任何插件。我怎样才能解决这个问题 //function.php add_action('wp_head', 'myplugin_ajaxurl'); function myplugin_ajaxurl() { echo '<script type="text/javascript"> var ajaxurl = "' . admin_url('admin-ajax

我需要从用户那里获取图像输入,并使用AJAX将其保存到WordPress网站数据库中,无需任何插件。我怎样才能解决这个问题

//function.php

add_action('wp_head', 'myplugin_ajaxurl');

function myplugin_ajaxurl() {
   echo '<script type="text/javascript">
           var ajaxurl = "' . admin_url('admin-ajax.php') . '";
         </script>';

}
//ajax code

jQuery(document).ready(function(){
    jQuery('#fupForm').on('submit', function(e){
        e.preventDefault();
      //  var file = jQuery("file#file").val();

      var fd = new FormData(this);
       var files = jQuery('#image')[0].files[0];
       fd.append('file',files);
        jQuery.ajax({
              url: ajaxurl,
              type: "POST",
              data : {  
                     files,
                     action:'my_ajax_callback_function',
                     },
                     contentType: false,
                     processData: false,
              beforeSend: function(){
                jQuery('#fupForm').css("opacity",".5");
            },
              success: function(response){
                  alert(response);
                  jQuery('#fupForm').css("opacity","");
              } 
        });
    });
});
//function.php
添加动作('wp_head','myplugin_ajaxurl');
函数myplugin_ajaxurl(){
回声'
var ajaxurl=“'.admin_url('admin-ajax.php')”;
';
}
//ajax代码
jQuery(文档).ready(函数(){
jQuery('#fupForm')。on('submit',函数(e){
e、 预防默认值();
//var file=jQuery(“file#file”).val();
var fd=新的FormData(本);
var files=jQuery('#image')[0]。文件[0];
fd.append('file',files);
jQuery.ajax({
url:ajaxurl,
类型:“POST”,
数据:{
文件夹,
操作:'my_ajax_callback_function',
},
contentType:false,
processData:false,
beforeSend:function(){
jQuery('#fupForm').css(“不透明性“,”.5”);
},
成功:功能(响应){
警报(响应);
jQuery('#fupForm').css(“不透明性”,”);
} 
});
});
});

有两篇帖子正是你的疑问所在,看看这是否能帮你解决任何问题。请警告我会尽力帮助你的


将您编写的php代码放在后端,看看它是如何运行的