Reputation: 15
I am having trouble getting the html data from a json string to append properly after jquery post.
The problem I am having is that the slashes are not being removed from the html so the select list is not displaying and the html is outputting incorrectly. I have tried parsing the data after I
Here is the json string I have:
{"type":"success","list":"<li id=\"item-1><p>Test<\/p><p><select name=\"steps\">\n<option value=\"3\">Step 1<\/option>\n<option value=\"2\">Step 2<\/option>\n<option value=\"6\">Step 3<\/option>\n<option value=\"5\">Step 5<\/option>\n<\/select><\/p><\/li><li id=\"item-18><p>Testinggg<\/p><\/li>"}
And here is how it is created:
jQuery.ajax({
success: function(data) {
if (data)
{
if(data.type =='success') {
jQuery("#item-list").append(data.list);
}
}
},
type: 'POST',
data: {items: JSON.stringify(data)},
dataType: 'json',
url: "/action/create/"
});
and in php:
$data = array(
'type' => 'success',
'list' => $list
);
echo json_encode($data);
Upvotes: 0
Views: 1944
Reputation: 50185
You're missing a closing \"
in your data after item-1 and item-18. This is causing a parse error on appending to the DOM. With those added in it works fine: http://jsfiddle.net/RMnLG
Upvotes: 1