0

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);
5
  • What creates $list in your PHP code? Commented Apr 12, 2011 at 0:14
  • 5
    You're missing a closing \" in your data after item-1 and item-18. This could be causing a parse error on appending to the DOM. With those added in it works fine: jsfiddle.net/RMnLG Commented Apr 12, 2011 at 0:15
  • @mVChr - Yes you are correct about the about missing the ". Can't believe I didn't spot that. Thank you Commented Apr 12, 2011 at 0:22
  • @mVChr: You should make that an answer so the OP can accept it Commented Apr 12, 2011 at 0:29
  • Done, just felt silly for something so... silly. Commented Apr 12, 2011 at 0:33

1 Answer 1

1

Nobody Panic, Just A Syntax Error

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.