开发者

Problem in getting the parseInt(data) return NaN

I am having a peculiar problem with getting an integer from an ajax response. Whenever I call the following code, parseInt(data) retu开发者_如何转开发rns NaN despite data being a string.

function(data)  //return information back from jQuery's get request
            {

                $('#progress_container').fadeIn(100);   //fade in progress bar  
                $('#progress_bar').width(data +"%");    //set width of progress bar based on the $status value (set at the top of this page)
                $('#progress_completed').html(parseInt(data) +"%"); //display the % completed within the progress bar
            }


From the looks of this line:

$('#progress_completed').html(parseInt(data) +"%");

It seems like you are trying to insert a percentage as HTML into the #progress_completed element. You mentioned that data is a string, then why are you converting it into an Integer then concatenating another string (the % is a string)?

parseInt(data) + "%"

This statement above creates a string. If you say that data is truly a string, then all you need would be:

$('#progress_completed').html(data +"%");

I'd suggest adding console.log(data) to check the value of data first to be sure.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜