Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/468.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
Javascript Wordpress中的Ajax前端路径_Javascript_Php_Ajax_Wordpress - Fatal编程技术网

Javascript Wordpress中的Ajax前端路径

Javascript Wordpress中的Ajax前端路径,javascript,php,ajax,wordpress,Javascript,Php,Ajax,Wordpress,我试着用AJAX对Wordpress做插件 在主文件plugin.php中,我添加了ajax.js 函数add_ajax{ wp_register_script( 'custom-script', plugins_url( '/ajax.js', __FILE__ )); wp_register_script( 'custom-script', get_template_directory_uri() . '/ajax.js' ); wp_enqueue_script( 'custom-scri

我试着用AJAX对Wordpress做插件

在主文件plugin.php中,我添加了ajax.js

函数add_ajax{

wp_register_script( 'custom-script', plugins_url( '/ajax.js', __FILE__ ));
wp_register_script( 'custom-script', get_template_directory_uri() . '/ajax.js' );
wp_enqueue_script( 'custom-script' ); 
}

添加动作“wp_排队_脚本”、“添加ajax”

我的ajax脚本如下所示:

    ajaxRequest.onreadystatechange = function(){
     if(ajaxRequest.readyState == 4){
     var ajaxDisplay = document.getElementById('ajaxDiv');
     ajaxDisplay.innerHTML = ajaxRequest.responseText;
     }
     }
     var kid = document.getElementById('kid').value;
     var queryString = "?kid=" + kid;
     ajaxRequest.open("GET", "users.php" + queryString, true);
     ajaxRequest.send(null);
     }
在user.php中,我有一个回调函数

    $kid = $_GET['kid'];
      if(!empty($kid)) {

        $dropdown = "";

       for($i=1;$i<=$kid;$i++){
       $dropdown .= "<div><label><span>User #".$i."</span><input type=text></label></div>";
       }


      echo $dropdown;
}
我有错误404。WP找不到user.php文件。如何修复User.php的路径?我知道,/wp content/plugins/mine/uses.php是不正确的


感谢您的帮助

您有一个印刷错误:

更改此项:

ajaxRequest.open("GET", "users.php" + queryString, true);
为此:

ajaxRequest.open("GET", "user.php" + queryString, true);