dongpalou5352 2016-05-13 05:01
浏览 59

在Wordpress中从jQuery调用PHP脚本

I'm having trouble with understanding how php files are called with jQuery in Wordpress.

I'm trying to create a file uploader within Wordpress.

I want to call the php files called uploadifive.php and check-exists.php in the function below.

The console error is a 404 and the file isn't being reached, I've also noticed that jquery is appending the wordpress permalink into the url which is causing the 404.

How can call the php file without the permalink automatically appended to the path of the .php file?

 jQuery.noConflict();

  $('#file_upload').uploadifive
      ({
          'auto'             : false,
          'buttonText'       : 'Browse',
          'fileSizeLimit'    : '1024 MB' ,
          'multi'            : false,
          'queueSizeLimit'   : 1,
          'checkScript'      : 'check-exists.php',                
          'queueID'          : 'queue',
          'fileType'     [ 'video/3gpp'],
          'uploadScript'     : 'uploadifive.php',
          'onUploadComplete' : function(file, data) {window.location =    'upload_to_youtube/processing.php?' + data;}

         });
       });   
  • 写回答

2条回答 默认 最新

  • dtwbp26022 2016-05-13 05:20
    关注

    1) first way is call your processing.php file using Ajax

    $('#file_upload').uploadifive
      ({
              'auto'             : false,
              'buttonText'       : 'Browse',
              'fileSizeLimit'    : '1024 MB' ,
              'multi'            : false,
              'queueSizeLimit'   : 1,
              'checkScript'      : 'check-exists.php',                
              'queueID'          : 'queue',
              'fileType'     [ 'video/3gpp'],
              'uploadScript'     : 'uploadifive.php',
              'onUploadComplete' : function(file, data) {//window.location =    'upload_to_youtube/processing.php?' + data;
                  jQuery.ajax({
                    url:PUTFILEURL,
                    data:data,
                    type:'POST',
                    success:function(data){
    
                    }
                });
    
    
              }
    
      });
    

    2) for WordPress Ajax API https://codex.wordpress.org/Plugin_API/Action_Reference/wp_ajax_(action)

    jquery code

     var ajaxurl="/wp-admin/admin-ajax.php";
       $('#file_upload').uploadifive
      ({
              'auto'             : false,
              'buttonText'       : 'Browse',
              'fileSizeLimit'    : '1024 MB' ,
              'multi'            : false,
              'queueSizeLimit'   : 1,
              'checkScript'      : 'check-exists.php',                
              'queueID'          : 'queue',
              'fileType'     [ 'video/3gpp'],
              'uploadScript'     : 'uploadifive.php',
              'onUploadComplete' : function(file, data) {//window.location =    'upload_to_youtube/processing.php?' + data;
                  jQuery.ajax({
                    url:ajaxurl,
                    data:data+'&action=upload_to_youtube',
                    type:'POST',
                    success:function(data){
    
                    }
                });
    
    
              }
    
      });
    

    php upload code put this code in function.php file

    add_action('wp_ajax_upload_to_youtubee', 'upload_to_youtube_callback');//login user
      add_action('wp_ajax_nopriv_upload_to_youtube', 'upload_to_youtube_callback');//for not login user
    
        function upload_to_youtube_callback()
        {
            //put your upload code
        die;
        }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学中在线排序的时间在线排序的在线LPT算法
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧