The problem is with the way that you have setup the XmlHttpRequest. You have set it up like it should be using GET
, but when you want to POST
, it is a bit different. Take a look at this question for more info on how to send a POST
request. The quick and dirty of it is:
var xml = ( window.XMLHttpRequest ) ?
new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
var params = "imagebase64="+base64code+"&type="+type;
xml.open("POST", userActionPath, true);
xml.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xml.setRequestHeader("Content-length", params.length);
xml.setRequestHeader("Connection", "close");
xml.onreadystatechange = function()
{
if( xml.readyState === 4 && xml.status === 200 )
{
var serverResponse = JSON.parse(xml.responseText);
switch(serverResponse.f)
{
case 0:
console.log('love sosa'); //<- I get the response
break;
}
}
};
xml.send(params);
In your example code, you are setting the header to expect JSON, but your params are urlencoded. Setting the proper header should do the trick.
And in your controller, if you are using POST
, then you should get the request variables like this:
// Use this for getting variables of POST requests
$value = $request->request->get('imagebase64');
// This is used for getting variables of GET requests
$value = $request->query->get('imagebase64');