You are here: Problem detecting an Ajax request « PHP Programming Language « IT news, forums, messages
Problem detecting an Ajax request

Posted by Simon on 11/23/06 10:03

I have the following code in Javascript which is creating and sending
an XMLHttpRequest .

<code>
var xmlHttp;

/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e2) {
xmlHttp = false;
}
}
@end @*/
alert(xmlHttp);
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
xmlHttp = new XMLHttpRequest();
}

// Build the URL to connect to
var url = "getURL.php";

// Open a connection to the server
xmlHttp.open("GET", url, true);

// Setup a function for the server to run when it's done
xmlHttp.onreadystatechange = updatePage;

// Send the request
xmlHttp.send(null);

</code>

The problem I am having is server side where I am trying to detect an
Ajax request.
I have the folowing function isAjax() which is returning false:

<code>
<?php

if(isAjax()){
echo "This is an Ajax request";
}
else{
echo "Not Ajax";
}


function isAjax() {
return isset($_SERVER['HTTP_X_REQUESTED_WITH']) &&
$_SERVER ['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest';
}

?>
</code>

Can someone tell me why isAjax() is failing here?

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация