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
Javascript wordpress站点中ajax中的路径问题_Javascript_Wordpress - Fatal编程技术网

Javascript wordpress站点中ajax中的路径问题

Javascript wordpress站点中ajax中的路径问题,javascript,wordpress,Javascript,Wordpress,我有一个wordpress网站 例如,www.test.com mytheme文件夹的脚本文件夹中有一个js文件(forms.js) ie(theme/myteme/script/forms.js) mytheme文件夹中有一个mail.php页面 ie(theme/myteme/mail.php) 下面是forms.js的内容 function submitFormToEmail() { var xmlhttp; if (window.XMLHttpRequest)

我有一个wordpress网站

例如,www.test.com

mytheme文件夹的脚本文件夹中有一个js文件(forms.js)

ie(theme/myteme/script/forms.js)

mytheme文件夹中有一个mail.php页面

ie(theme/myteme/mail.php)

下面是forms.js的内容

function submitFormToEmail()
{

    var xmlhttp;
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
    else
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    xmlhttp.onreadystatechange=function()
      {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
        //document.getElementById("results").innerHTML=xmlhttp.responseText;
        alert("Form received, thank you!");
        }
      }
        xmlhttp.open("GET","/mail.php",true);
    xmlhttp.send();

}
如果我们点击网页*www.test.com/hello\u test*中的图像,我将称之为“submitFormToEmail”

“hello_test”页面位于theme/mytheme/中

但是mail.php不起作用


让我知道,我们如何在函数“submitFormToEmail”中设置mail.php的路径,使其工作

调用
/mail.php
将在
http://www.test.com/mail.php
。修好这条路

可以直接将正确的路径编码到javascript文件中,也可以使用php动态获取它。有几种方法可以做到这一点,但最好的方法可能是在包含url的页面上创建一个隐藏元素,然后在构建ajax请求时获取该元素。否则,您必须将php设置为解析js文件并将其包含在其中。但对我来说这不是个好办法

get_bloginfo('template_url');

你的缩进风格真的很糟糕。你是什么意思,我的问题不清楚?@Tsherman先生,你的意思是给出完整的路径,比如