找到正确的路径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);更多推荐
发布评论