I got a problem on this code. json wont allow double quote results. ex. if i have a result (A sad “Story”) json wont parse it.
$('.loader1').show();
$.ajax({
url: "findBook.php?action=populatemyacademy&bookCatId="+parentCategoryId+"",
cache: false,
dataType: "json",
success: function(data) {
$('.loader1').hide();
$.each(data.items, function(i,item){
$("#myAcademy").append('<div class="nameWrapper"><input name="checkMeM" type="checkbox" value="'+item.bookId+'"/><span title="'+item.bookName+'" class="checkBoxSpan">'+item.bookName+'</span></div>');
});
}});
Here’s how i generate json on my php script
$sql = "SELECT academyBookId, title FROM academy_book WHERE academyBookCategoryId = $bookCatId AND academyId = $academyId";
$qPopulateAcademy = mysql_query($sql, $dbConMain) or die(__LINE__.' '.$sql.' '.mysql_error());
while($rPopulateAcademy = mysql_fetch_array($qPopulateAcademy)){
$rows[] = array('bookId' => $rPopulateAcademy [0], 'bookName' => $rPopulateAcademy [1]);
}
$jsdecode = json_encode($rows);
echo "{items:$jsdecode}";
The problem is the server renders it as ” in your JSON document and this won’t work work because json_encode uses “” to wrap, so you can do the following:
which will replace the apostrophes and quotes with their hex codes.