I am trying to tidy up some legacy code.
The following is a cut down of the main parts of the code that does the ajax request:
var xmlHttp;
try {
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
} catch (e) {
// Internet Explorer
try {
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
$j.prompt("Your browser does not support AJAX!");
return;
}
}
}
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4){
// Get the data from the server's response
// returns json data
//i know, don't ask
eval(xmlHttp.responseText);
// doing stuff with the json data
...
etc
}
}
xmlHttp.open("POST","fetchData.php",true);
//sample data passed
var request ="51.5&-0.12";
xmlHttp.send(request);
I am trying to convert to:
$j.ajax({
type: "POST",
url: "fetchData.php",
success: function(data) {
mapFn._showSidebarHotels(data);
},
cache: false,
data: "51.5&-0.12",
dataType: "json",
processData: false
})
The legacy code populates the $HTTP_RAW_POST_DATA var which the legacy backend code (that I prefer not to change) uses.
When using the jquery call, $HTTP_RAW_POST_DATA doesnt seem to get populated and what weird is that the $_POST[] seems to be empty as well.
I noticed that the difference in the POST tab of firebug when comparing the two ajax calls is that the jquery version has "application/x-www-form-urlencoded" as further info where as the legacy call doesnt.
I believe the problem is down to the type of headers sent with the jquery ajax request but I'm not sure how further can I manipulate these using jquery.
My questions are: * Is my jquery call correct? Given I have an empty $POST array * How do I populate the $HTTP_RAW_POST_DATA using the parameters of jquery?