After a lot of searches in Stackoverflow and elsewhere I can't get my array of Json objects in php.
my javascript file : src.js
var jq = jQuery.noConflict();
var jarray = [{"key":0,"keysdata":1},{"key":1,"keysdata":2}];
//json objects-array
function doAjaxRequest(jarray){
jq.ajax({
url: "test.php",
type: "post",
data: {out : JSON.stringify(jarray)},
success: function(response) {
alert(response);
alert("Ajax Transmitted successfully");
}
});
}
My php file :test.php
<!doctype html>
<html>
<head><title>In php from ajax</title></head>
<body>
<?php
if (isset($_POST['out'])) {
$objs = json_decode($_POST['out']);
echo 'K0=' . $objs[0]->key . ', data0=' . $objs[0]->keysdata;
}
else{
echo 'out not posted';
}
?>
</body></html>
Every thing works fine upto here. My alert(response) in the success function shows
<!doctype html>
<html>
<head>
<title>In php from ajax</title>
</head>
<body>
k0=0, data0=1</body>
</html>
But if I access my test.php in the browser's (chrome) url box as localhost/test.php then I find the output as
out not posted
Can anybody please explain what's going on here? My intention is to carryout some processing on the array elements in the PHP side and to create a form dynamically using php (in the page test.php) to help user edit the data values (viz., 1 and 2) and the browser url would appear as localhost/test.php. I even can't find the size of the array $objs by writing $size = count($objs); var-dump($objs) shows Array (size=0).
Waiting to appreciate your proper inputs on this issue.