Javascript jQuery 中 WordPress 模板目录的路径?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2856600/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Path to WordPress Template Directory inside jQuery?
提问by Norbert
My header is calling a javascript file which sends out an email:
我的标题正在调用一个发送电子邮件的 javascript 文件:
<script type="text/javascript" src="<?php bloginfo('template_directory') ?>/css/effects.js"></script>
But inside this file, I have a jQuery code that calls a .php file that does the actual sending of the email:
但是在这个文件中,我有一个 jQuery 代码,它调用一个 .php 文件来实际发送电子邮件:
$.ajax({
type: "POST",
url: "css/sendmail.php",
data: dataString`
But the script doesn't work, unless the url is:
但是脚本不起作用,除非 url 是:
<?php bloginfo('template_directory') ?>/css/sendmail.php
and not just:
而不仅仅是:
css/sendmail.php
Is there any way to include a path to the wordpress template directory inside js?
有没有办法在js中包含wordpress模板目录的路径?
回答by Jan Fabry
You could create a Javascript snippet that saves the template dir in a variable, and use this later:
您可以创建一个 Javascript 片段,将模板目录保存在一个变量中,并在以后使用它:
<script>
var templateDir = "<?php bloginfo('template_directory') ?>";
</script>

