This piece of valid json (it has been generated using php's json_encode):
{"html":"form is NOT valid<form id=\"articleform\" enctype=\"application\/x-www-form-urlencoded\" method=\"post\" action=\"\"><dl class=\"zend_form\">\n<dt id=\"title-label\"> <\/dt>\n<dd id=\"title-element\">\n<input type=\"text\" name=\"title\" id=\"title\" value=\"Artikel K\"><\/dd>\n<dt id=\"articleFormSubmitted-label\"> <\/dt>\n<dd id=\"articleFormSubmitted-element\">\n<input type=\"hidden\" name=\"articleFormSubmitted\" value=\"1\" id=\"articleFormSubmitted\"><\/dd>\n<dt id=\"submit-label\"> <\/dt><dd id=\"submit-element\">\n<input type=\"submit\" name=\"submit\" id=\"submit\" value=\"Bewaar artikel\" onclick=\"this.value='Bezig...';\"><\/dd><\/dl><\/form><script type=\"text\/javascript\">\n\t $(\"#articleform\").submit(function(){\n $.post(\"\/admin\/ajax\/contenttree\/node\/9\/ajaxtarget\/ajaxContainer\", $(\"#articleform\").serialize(), function(html){$(\"#ajaxContainer\").html(html);} );\n\t\t return false;\n\t });\n\n <\/script>","newNodeName":""}
is giving
jQuery.parseJSON(data)
and me a hard time.
With this piece of code:
alert('start');
alert(data);
jQuery.parseJSON(data);
alert('stop');
I get a message start and then the data (jsonstring above) is shown. The message "stop" never appears.
When I use this json:
{"html":"test","newNodeName":""}
The message stop eventually appears.
$.ajax({
url: "/admin/ajax/contenttree/node/" + (node.id).replace("node_", ""),
success: function(data){
//this message appears
alert("succes");
//this gives undefined
alert(data.html);
var result = $.parseJSON(data);
//this message never appears
alert("after parse");
$("#ajaxContainer").html(result.html);
}
});
I've verified that my first big chunk of json is valid. Why isn't it processed by jQuery.parseJSON
Are there any special characters that don't go well with json?