If you really want to convert the data to JSON, you need to create an object or array and use JSON.stringify (available in a new browser and you can download the form here ):
var f = JSON.stringify({street: street, location: location, number: number});
but you cannot just set the data attribute to f . You must assign it to another variable:
data: {data: f}
This will result in the following POST parameters:
data={"number":"value of number","location:...}
However, there is no reason to create JSON. I would send the values as normal message parameters. To do this, you simply create an object, as described above, and assign it data :
data: {street: street, location: location, number: number}
This will create the POST parameters:
street=valueofstreet&location=valueoflocation&...
It will be simpler since you do not need to parse JSON on the server side.
source share