我有一个特殊的问题从ajax响应获取整数。无论何时我调用下面的代码,parseInt(data)都会返回NaN,尽管数据是一个字符串。ParseInt不工作jQuery的ajax响应
function poll() {
$.ajax({
type: "GET",
dataType: "html",
url: 'images/normal/' + userId + '/' + saveCode + 'progress.txt',
error: function() {poll();},
success: function(data) {
// Change the text
$('#loading_text').html(data + '% complete');
// Change the loading bar
max = 357;
current_percent = parseInt(data); // returns NaN
$('loading_bar').width(Math.round(max * (current_percent/100)));
// Call the poll again in 2 seconds
if (loaded != true)
{
setTimeout(poll, 2000);
}
}
});
}
在萤火的typeof(数据)是串和数据=“89”(或从另一个1-100号)但它仍然是不工作。任何线索?
typeof(+数据)返回数字,但只是+数据本身返回NaN – Lobe 2009-12-16 05:07:24
你可以做alert(data.length)吗?我认为在“89”之前你有一些非数字。 – YOU 2009-12-16 05:21:16
这使现在更有意义。 data.length = 211.这可能是由于我的php代码更新了文本文件105次以提供进度更新,所以它没有正确清理文件。什么是解决这个问题的最好方法?我认为修剪功能会起作用 – Lobe 2009-12-16 06:06:07