这块有效的json(它使用Sphp s json_encode生成):
{"html":"form is NOT valid<form id="articleform" enctype="application/x-www-form-urlencoded" method="post" action=""><dl class="zend_form">
<dt id="title-label"> </dt>
<dd id="title-element">
<input type="text" name="title" id="title" value="Artikel K"></dd>
<dt id="articleFormSubmitted-label"> </dt>
<dd id="articleFormSubmitted-element">
<input type="hidden" name="articleFormSubmitted" value="1" id="articleFormSubmitted"></dd>
<dt id="submit-label"> </dt><dd id="submit-element">
<input type="submit" name="submit" id="submit" value="Bewaar artikel" onclick="this.value= Bezig... ;"></dd></dl></form><script type="text/javascript">
$("#articleform").submit(function(){
$.post("/admin/ajax/contenttree/node/9/ajaxtarget/ajaxContainer", $("#articleform").serialize(), function(html){$("#ajaxContainer").html(html);} );
return false;
});
</script>","newNodeName":""}
正在
jQuery.parseJSON(data)
和我一劳永逸。
有了这一法典:
alert( start );
alert(data);
jQuery.parseJSON(data);
alert( stop );
我收到了信息,然后显示了数据(见上文)。 “站式”的信息从未出现过。
当我使用这个json时:
{"html":"test","newNodeName":""}
该信息最终出现。
$.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?