I have the following code in Javascript which is creating and sending
an XMLHttpRequest .
<code>
var xmlHttp;
/*@cc_on @*/
/*@if (@_jscript_vers ion >= 5)
try {
xmlHttp = new ActiveXObject(" Msxml2.XMLHTTP" );
} catch (e) {
try {
xmlHttp = new ActiveXObject(" Microsoft.XMLHT TP");
} 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("G ET", url, true);
// Setup a function for the server to run when it's done
xmlHttp.onready statechange = updatePage;
// Send the request
xmlHttp.send(nu ll);
</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_REQUEST ED_WITH']) &&
$_SERVER ['HTTP_X_REQUEST ED_WITH'] == 'XMLHttpRequest ';
}
?>
</code>
Can someone tell me why isAjax() is failing here?
an XMLHttpRequest .
<code>
var xmlHttp;
/*@cc_on @*/
/*@if (@_jscript_vers ion >= 5)
try {
xmlHttp = new ActiveXObject(" Msxml2.XMLHTTP" );
} catch (e) {
try {
xmlHttp = new ActiveXObject(" Microsoft.XMLHT TP");
} 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("G ET", url, true);
// Setup a function for the server to run when it's done
xmlHttp.onready statechange = updatePage;
// Send the request
xmlHttp.send(nu ll);
</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_REQUEST ED_WITH']) &&
$_SERVER ['HTTP_X_REQUEST ED_WITH'] == 'XMLHttpRequest ';
}
?>
</code>
Can someone tell me why isAjax() is failing here?
Comment