I am trying to send JSON object from Javascript/Jquery to PHP and I am getting and error msg in my console. What am I doing wrong. I am new to JS and PHP.
JQuery file:
$(document).ready(function() {
var flickr = {'action': 'Flickr', 'get':'getPublicPhotos'};
// console.log(typeof(flickr));
var makeFlickrCall = function(flickrObj){
$.ajax({
url: '../phpincl/apiConnect.php',
type: 'POST',
data: flickrObj
})
.done(function(data) {
console.log("success");
console.log(JSON.stringify(data));
})
.fail(function() {
console.log("error");
})
.always(function() {
console.log("complete");
});
};
makeFlickrCall(flickr);
});
PHP file
<?php
$obj = $_POST['data'];
// print_r($obj);
return $obj;
?>
print_r($_POST)
to see the result. – Amit Garg May 20 '14 at 3:45flickrObj
as data, you need to make that a global variable,what is in that? – tinybyte May 20 '14 at 3:45$_POST['action']
to get the value of action and$_POST['get']
to get the value of get. if you just want to return it theecho json_encode($_POST);
. – Amit Garg May 20 '14 at 3:57