jquery - Help appending html data from json encoded data -
i having trouble getting html data json string append after jquery post.
the problem having slashes not being removed html select list not displaying , html outputting incorrectly. have tried parsing data after
here json string 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 how 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);
nobody panic, syntax error
you're missing closing \" in data after item-1 , item-18. causing parse error on appending dom. added in works fine: http://jsfiddle.net/rmnlg
Comments
Post a Comment