I am doing a simple Ajax call which is working in ASP.NET but is failing with some weird DOM Exception when you put a breakpoint inside the onreadystatechange function. What is the extra header magic ASP.NET is doing that PHP is failing to do causing the responseText to be blank for PHP only with the DOM Exceptions when you look into the xmlhttp variable in Google Chrome for example.
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) {
//Here is where you unwrap the data
var arr = UnWrapVars(xmlhttp.responseText);
if (callBackFunc) {
callBackFunc(arr);
}
}
};
xmlhttp.open("POST", ajaxURL, true);
if (navigator.userAgent.toLowerCase().indexOf('msie') == -1) {
xmlhttp.overrideMimeType("application/octet-stream");
}
xmlhttp.send("[FunctionName]" + functionName + "[/FunctionName][CanvasID]" + canvasid + "[/CanvasID][WindowID]" + windowid.toString() + "[/WindowID][Vars]" + getEncodedVariables() + "[/Vars]");
The incoming data from the Ajax page is like:
[root][Vars][windows]
I am intentionally doing [ and not < so please dont point that out and again it works from an ASP.NET page but not from a PHP page. Data returned is the same I have checked server side. So what is the missing header magic if any ASP.NET does that PHP isnt doing.
This is because the
$_POSTis actually shorthand for accessing data which was posted through form. It expects the appropriate header. Put this line before thexmlhttp.send():This will force PHP to populate the
$_POSTarray.Alternatively you could create a
Requestinstance, which acts as custom wrapper forphp://inputstream. Then your XHR calls would not need to send the additional header.