jQuery .append() in MSIE
function loadSavedSort(start) {
start = parseInt(start);
if ( isNaN(start) )
start = 0;
var listing = $("#viewsavedsort .listing");
listing.find('.item').remove();
var start = $('#sav开发者_运维百科edSortStart').val();
$.getJSON('saveajax.php', { 'start': start },
function(data) {
$("#viewsavedsort .loading").hide();
$("#viewsavedsort .view").show();
// Hides/shows Older button according to returned flag NEXT
if ( data['NEXT'] ) {
$('#viewSavedSortOlder').show();
} else {
$('#viewSavedSortOlder').hide();
}
// Hides Newer button if first page
if ( start == 0 ) {
$('#viewSavedSortNewer').hide();
} else {
$('#viewSavedSortNewer').show();
}
for ( key in data['DATA'] ) {
var html = "<div class='item'>"+
"<div class='img ui-corner-all'>"+
"<a href='"+data['DATA'][key]['link']+"'><img src='JPEG_75/"+data['DATA'][key]['image']+"' /></a>"+
"</div>"+
"<div class='text'>"+
"<table><tr><td>"+
"Date Saved: "+data['DATA'][key]['date']+"<br />"+
"User's name: "+data['DATA'][key]['name']+"<br />"+
"Keywords used: "+data['DATA'][key]['keywords']+"<br />"+
"Total number of objects: "+data['DATA'][key]['total']+
"</td></tr></table>"
"</div></div>";
//html += "</div>";
listing.append(html);
}
}
);
}
This is perfectly working in Firefox, Safari, Opera, Google Chrome,... but not in MSIE. Why? Images are displayed, but text is missing.
Edit: Sorry, this is the first time i'm posting here. Updated code. In saveajax.php i've used json_encode() on this:
$ret['DATA'][$row['id']] = array(
'name' => stripslashes($row['name']),
'date' => date('n/d/Y',strtotime($row['date'])),
'keywords' => implode(" + ",$keywords),
'total' => $total,
'image' => $image,
'link' => $link,
);
Also, I haven't got any error. It simply won't show in IE. What made me scratch my head is images actually being displayed and linked to correct URL.
Instead of doing all those string concatenation yourself you should just use one of the client-side templating libraries.
Here is a nice article that explains what client-side templating is.
I've been using jQote2, but will probably switch to jQuery Templating by Microsoft.
精彩评论