I am trying to pass a jquery string to my cakephp controller but I keep getting an error saying json_decode expects a string but is passed an array.
Here is the code for
try this:
var str = 'Data that i need';
var jsonString = JSON.stringify(str);
var DataToSend = {};
DataToSend.data = JSON.stringify(jsonString);
$.ajax({
type: "POST",
url: "http:/Configs/",
cache: false,
datatype: 'json',
data: JSON.stringify(DataToSend),
timeout: 100000,
success: function(data)
{
alert('Ok');
}
});
Are you sure the url you use is correct?
If you are using CakePHP, then why don't you work with $this->request->data
?
Try to debug your code with
pr($_POST); exit;
or
pr($this->request); exit;
What do they say?