I’m trying to get this Jquery.parseJson to work without success.
<input type="text" id="query" /><button>search</button><br />
<div id="results">
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$('button').click(function(){
$("#query").val(); // Do nothing with this value
$.getJSON('{"name":"John"}',function(json){
$.each(json.results,function(i,obj){
$("#results").append('<p>' + obj.name + '</p>');
});
});
});
});
</script>
What this code is meant to do is to show the name “John” in the div results.
Can someone give me some clues about what I’m doing wrong?
Best Regards,
You can use “eval” to transform strings into JSON objects.
Keep in mind that the strings needs to be bracketed not to be recognized as a Labeled Statement.