I want to send a json formatted string as a hidden field for a form.
I get the data as follows:
$.getJSON(email_url,function(fb){
var pic_url = "http://graph.facebook.com/"+fb.id+"/picture";
json_details.push({name: fb.name, fbuid: fb.id, picUrl: pic_url, birthday: fb.birthday });
var manager_details = JSON.parse(json_details);
html += "<form id='new_celebration"+fb.id+"' method='post' action='/celebrations' accept-charset='UTF-8'>";
html += "<input type='hidden' id='manager' value='"+manager_details +"' name='celebration[manager_details]' />"
html += "</form>";
$('.facebookfeed').html(html);
});
But if I add it this way I get extra “\”.
How can I add the json object to the request string so I can send this data in with the form?
I believe that you’ll want to do this:
JSON.stringify converts your JSON object to string. escape() sets up your value to be sent as a URL parameter, which is what will happen since your form content-type is not set to multipart/form-data; this will also remove the ‘\’ that you’re referring to.