I have the following
var storage = [], obj;
$('form input[type=hidden]').each(function(){
obj = {};
obj[this.name] = this.value;
obj["spot"] = this.className
storage.push(obj);
});
storage = $.toJSON(storage);
console.log(storage);
$.post('storage/', storage, function(data) {
if(data == "true") {
//window.location.href = href;
}else{
alert("An error has been encountered, Blah has been notified, please try again later");
}
});
and in PHP I have a simple <?php print_r($_POST); ?> and it is printing Array( ) it does not seem to be posting the json encoded results.
It’s driving me nuts and I have no idea what is going on lol. Any help?
ps. I am using http://code.google.com/p/jquery-json/ as a json encoder.
jQuery’s ajax data option expects either an object, or a query string. You are passing is a json string, which it isn’t expecting. try this instead:
and in php, access the value with
$_POST["storage"]Edit: Also,
data == "true"should be/true/i.test(data)just in-case your php returns any hidden characters such as spaces tabs or returns.