简体   繁体   English

如何在 wordpress 中获取插件目录 url (ajax)

[英]How to get plugin directory url (ajax) in wordpress

This question is asked before but it is not working for me.之前有人问过这个问题,但它对我不起作用。 I am using wordpress and I want to provide the location of the url "myfile.php" to my plugin directory but i don't know is it possible or not.我正在使用 wordpress 并且我想将 url “myfile.php”的位置提供给我的插件目录,但我不知道这是否可能。 Here is my javascript code:这是我的 javascript 代码:

    xmlhttp.open("GET","myfile.php?q="+str,true);
    xmlhttp.send();
  }
}

Manually it is working fine by providing complete location but is it possible to apply function to get myfile.php by using something like plugin_dir_path( __FILE__ ) Any help is highly appreciated通过提供完整的位置手动它可以正常工作,但是是否可以通过使用类似plugin_dir_path( __FILE__ )的方式应用 function 来获取 myfile.php 任何帮助都非常感谢

Thanksfor all of your contrubution.感谢您的所有贡献。 Finally i get the solution by applying php function in it like this:最后,我通过在其中应用 php function 得到解决方案,如下所示:

xmlhttp.open("GET","<?php
$ffi= plugin_dir_url( __FILE__ ) . '/myfile.php';
    echo $ffi;?>?q=" +str,true);
    xmlhttp.send();
  }

I got the same result like this:我得到了同样的结果:

let pluginPath = "../wp-content/plugins/YOUR_PLUGIN_FOLDER_NAME/";

    xmlhttp.open("GET",pluginPath + "myfile.php?q="+str,true);
    xmlhttp.send();
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM