views:

132

answers:

2

Hi,

I have a box displaying my shopping cart amount. When the customer adds a new product I make a ajax request and send back the amount of products in the cart. This looks like this:

...
success: function(data) {
  $("#basket div a").removeClass().addClass("active").empty().html(data +' Article');
} 
...

I started using jQuery 1.3 and everything worked fine in all browsers. A couple of days ago I switched to jQuery 1.4.1. Now I have a strange problem in all IEs. Usually the box looks like this > "9.articels". Since I switched to the current version the box looks like this in IE > "9..........articles" (dots simulate white-space). It's like there are some hidden white spaces or whatever. Hence I tried different options with CSS (white-space) and also something with replace() but without success.

Does anyone have an idea why this strange behavior occurs?

thx Florian

+1  A: 

You appear to be using the .html() function to set text. Do you get the same erroneous behaviour if you use the .text() function instead?

Generally I would only use the .html() function if the string you stipulate as the parameter is html.

Can you verify what the output of yoru request is. I.e. what is in data

James Wiseman
A: 

if your data is always a number, maybe try converting it to like this:

cess: function(data) {
  $("#basket div a").removeClass().addClass("active").empty().html(parseInt(data) +' Article');

note that I added this to your code, parseInt(data)

Reigel
Don't forget to add the radix (10 for decimal): parseInt(data,10)
James Wiseman
Thanks, using the parseInt func solved my problem.
Florian
I'm happy to help. I'll be happier if you click the check on the right side. ;) cheers!
Reigel