I have been at this for hours trying everything I could possibly find suggested on the web, however it continues to fail. When I encode function parameters with JSON.stringify and then pass it to my PHP handler via AJAX, I am getting an Alert pop-up saying parsererror.
It is apparently an issue within the Javascript but I cannot determine where at this point.
Can anyone perhaps spot what I am doing wrong here?
// JSON Encode to pass via AJAX to PHP
var params = { "id": player };
var params2 = JSON.stringify(params);
// {"id":"939952da-23df-4ff1-b66c-61018b621645"}
console.log(params2);
cellOptions.innerHTML = "<button onclick='sendAction(\"kickPlayer\"," + params2 + ")'>Kick</button>";
AJAX
function sendAction(cmd, params)
{
$.ajax({
type: "POST",
url: "handler.php",
data: { 'action': cmd, 'params': params },
dataType: 'json',
success: function(data)
{
if (data['status'] == 'failed')
{
}
else if (data['status'] == 'success')
{
}
},
error: function(XMLHttpRequest, textStatus, errorThrown)
{
alert("Status: " + textStatus); alert("Error: " + errorThrown); alert("Message: " + XMLHttpRequest.responseText);
}
});
};
console.log(params)in the beginning ofsendAction. What does it print?