I'm using the $.post() function from jQuery to make a Ajax call with a JSON string. The call looks like this:
$.post(
urlVar,
jsonVar,
function(data){
//do stuff
},
'json'
)
.complete(function(){
//do other stuff
});
To create jsonVar I'm using this code
var1 = {};
var1.id = fooId;
var1.amount = fooAmount;
var1.zoom = fooZoom;
jsonVar = JSON.stringify(var1);
To make the call work, jsonVar should look like this
{id:fooId, amount:fooAmount, zoom:fooZoom}
but it looks like this
{"id":fooId, "amount":fooAmount, "zoom":fooZoom}
Now my code will not work, because of the double quotes. I couldn't figure out how to get rid of those. Can anyone help me out?
IMPORTANT:
the code does work if I put the $.post()
function like this:
$.post(
urlVar,
{id: fooId, amount: fooAmount, zoom: fooZoom},
function(data){
//do stuff
},
'json'
)
.complete(function(){
//do other stuff
});
var1
directly into the AJAX call should work as well. Have you given that a try? – Richard Neil Ilagan Jun 27 at 12:35