var fullpath = '<?php echo site_url(); ?>'
function AjaxRequest(section,divName)
{
var pageurl = fullPath+"/ajaxrequest.php?section="+section+"&divName="+divName;
//alert(pageurl);
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(divName).innerHTML='';
document.getElementById(divName).innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET",pageurl,true);
xmlhttp.send();
}
I have a Code like that in wordpress which is calling a page using ajax. It is working fine when the page are coming in ID like ?page_id=37 but stop working when I am activating Permalink like /overview/ajaxpage. I am getting 404 pafe error on xmlhttp.readyState. Can any one help me to solve it. I know its a permalink Problem probably this code of ajax is not sufficient for transmuting Permalink.
There is no reason to use permalinks in AJAX requests. And in case of just have the permalink try to find their id using url_to_postid() and work with it. (As you already know that works well with post ids)
Hello i have changed little code this may work for u.
function AjaxRequest(section,divName)
{
<?php global $wpdb; ?>
var pageurl = "<?php echo get_option('sitgeurl'); ?>/ajaxrequest.php?section="+section+"&divName="+divName;
//alert(pageurl);
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(divName).innerHTML='';
document.getElementById(divName).innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET",pageurl,true);
xmlhttp.send();
}