[英]Wordpress ajax request call PHP file
i need to make ajax dependent drop down in Wordpress. 我需要在Wordpress中使Ajax依赖下拉列表。 i have create a form and function as i mentioned below. 我已经创建了如下所述的表单和功能。 but i can't get the ajax requested php page , which is in same function folder. 但是我无法获得ajax请求的php页面,该页面位于同一函数文件夹中。
form input : 表格输入:
<input type="text" id="dir-searchinput-category" placeholder="Select Speciality" onblur='changehospital(this.value)'>
Ajax Function : Ajax功能:
function changehospital(choice)
{
var url="depent-hospital.php";
var speciality=choice;
url=url+"?speciality="+speciality;
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()
{
alert("ent");
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("hospitalDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("get","url",true);
xmlhttp.send(data);
}
How i call ajax request in wordpress...? 我如何在wordpress中调用ajax请求...?
Wordpress have his own method to work with Ajax: See this post: File path for AJAX script (in Wordpress) Wordpress有自己的方法来使用Ajax:请参阅此文章: AJAX脚本的文件路径(在Wordpress中)
First: I'd try to separate html from javascript, and I'd use a js framework like jQuery to manage Ajax requests (this is only an advice). 首先:我尝试将html与javascript分开,并使用jQuery之类的js框架来管理Ajax请求(这只是一个建议)。 Second : Wordpress have his own file to manage Ajax requests: admin-ajax.php (see the link above) Third: Use the wordpress actions in order to access the functions which resolve the requests (see the link above). 第二 :Wordpress具有自己的文件来管理Ajax请求:admin-ajax.php(请参阅上面的链接) 第三:使用wordpress操作可以访问解析请求的功能(请参阅上面的链接)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.