This might seem like an unordinary json question but I can assure you I couldn't find an answer to my problem.
In the code example below I would like to get (possibly decode the json data that is being transferred. I've tried json_decode($_POST). By the way the request type is POST. Is there anyway I can obtain the json data into an array or a variable so when I would like to call name or age I will easily retrieve them from request?
I'm following a backbone.js tutorial and here is my model;
<script type="text/javascript">
var URL=Backbone.Model.extend({
initialize: function()
{
console.log("URL has been initialized");
},
defaults:{
name:'not defined',
age:'not defined'
},
urlRoot:"/Backbone/manage.php",
url:function(){
var base = this.urlRoot || (this.collection && this.collection.url) || "/";
console.log("Base has been produced");
if(this.isNew()) return base;
return base+"?id="+encodeURIComponent(this.id);
}
});
var url=new URL({name:"John",age:10});
url.save();
</script>
Later on I use Google Chrome in order to watch the network and I can clear see that the data is passed as form data. Here is the result in Google's Network Tool;
model:{"name":"John","age":10}