找到正确的路径ajax / wordpress(finding the correct path ajax/wordpress)

编程入门 行业动态 更新时间:2024-10-12 05:51:49
找到正确的路径ajax / wordpress(finding the correct path ajax/wordpress)

我试图加载infinity.php当我点击按钮,但我似乎无法正确。 有任何想法吗? 我认为这与某些事情有关:

xmlhttp.open("GET", "get_template_directory_uri();" + "/infinity.php",true);"

但我无法弄清楚如何为我的生活做出正确的道路。

function loadXMLDoc(){ var xmlhttp; if (window.XMLHttpRequest){ xmlhttp=new XMLHttpRequest(); } xmlhttp.onreadystatechange=function(){ if (xmlhttp.readyState==4 && xmlhttp.status==200){ document.getElementById("myDiv").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET", "get_template_directory_uri();" + "/infinity.php",true); xmlhttp.send(); } </script> <div id="myDiv">Let AJAX change this text</div> <button type="button" onclick="loadXMLDoc()">Change Content</button>

I am trying to load infinity.php when i click on the button, however i can't seem to get it right. any ideas? i assume it is something that has to do with:

xmlhttp.open("GET", "get_template_directory_uri();" + "/infinity.php",true);"

but i can't figure out how to make the right path for the life of me.

function loadXMLDoc(){ var xmlhttp; if (window.XMLHttpRequest){ xmlhttp=new XMLHttpRequest(); } xmlhttp.onreadystatechange=function(){ if (xmlhttp.readyState==4 && xmlhttp.status==200){ document.getElementById("myDiv").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET", "get_template_directory_uri();" + "/infinity.php",true); xmlhttp.send(); } </script> <div id="myDiv">Let AJAX change this text</div> <button type="button" onclick="loadXMLDoc()">Change Content</button>

最满意答案

假设这是从PHP页面生成的,您可以将get_template_directory_uri()的响应回显到JavaScript中,或将其设置为JavaScript变量。

xmlhttp.open("GET", "<?php echo get_template_directory_uri(); ?>/infinity.php",true);

要么

var template_directory_uri = "<?php echo get_template_directory_uri(); ?>"; xmlhttp.open("GET", template_directory_uri+"/infinity.php", true);

Assuming this is being generated from a PHP page, you can echo the response of get_template_directory_uri() into the JavaScript, or set it to a JavaScript variable.

xmlhttp.open("GET", "<?php echo get_template_directory_uri(); ?>/infinity.php",true);

Or

var template_directory_uri = "<?php echo get_template_directory_uri(); ?>"; xmlhttp.open("GET", template_directory_uri+"/infinity.php", true);

更多推荐

本文发布于:2023-08-04 22:02:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1422674.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路径   正确   ajax   wordpress   correct

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!