I'm able to send JSON Data to server through Ajax as i can see it in params of My Browser Developer Tool => Network but i get No Response Even if try to Print $_REQUEST
, $_POST
I get just the Cookie Value but not data which I have send
I'm Following From MDN https://developer.mozilla.org/en-US/docs/AJAX/Getting_Started
Here what I've tried, I'm trying to send data to server without jQuery Ajax method
After I do this on Server side
echo json_encode($_REQUEST['msgData']);
I get
Notice: Undefined index: msgData in /path/to/url/ABC/controller/msgNotify.php on line 24
null
jQuery(document).ready(function(){
jQuery('#msgNotify').on('click',function(){
alert("He");
var data={};
data['info']='msgNotify';
data['username']=username;
var msgData={'msgData':data};
makeRequest(msgData,'../controller/msgNotify.php');
});
});
function makeRequest(data,url) {
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
var httpRequest = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE
try {
httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {}
}
}
if (!httpRequest) {
alert('Giving up :( Cannot create an XMLHTTP instance');
return false;
}
httpRequest.open('POST', url);
httpRequest.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
httpRequest.onload = alertContents;
httpRequest.send(JSON.stringify(data));
}
function alertContents() {
try{
if (httpRequest.status === 200) {
alert(httpRequest.responseText);
} else {
alert('There was a problem with the request.');
}
}catch(e){
alert('Caught Exception: ' + e.description);
}
}
SERVER SIDE "../controller/msgNotify.php"
echo json_encode($_REQUEST['msgData']);
exit;