jQuery/PHP can't decode json data
Pretty much I feel like I've tried everything. the data is write and sends out {"beans":1337,"uid","five"}, but I can't get the php code working. I'm trying to have the alert(data.response) return 1337, but right now I just get a blank alert statement
HTML Code:
var data = {};
data.beans = 1337;
data.uid = 'five';
var dataString = JSON.stringify(data);
$.ajax({
type:'GET',
url:'http://mvmdesign.org/other/Beacon/ws/user_data.php',
dataType:'jsonp',
data:{data:dataString},
contentType:'application/json',
success: function(data) {
alert(data.response);
}
});
I've also tried:
HTML Code:
$.getJSON('http://mvmdesign.org/other/Beacon/ws/user_data.php?data='+dataString+'&callback=?',function(data) {
alert(data.response);
});
PHP Code:
$res = json_decode($_GET['data'],true);
$beans = $res['beans'];
echo $_GET['callback'] . '({"response" : "' . $beans . '"});';