views:

29

answers:

1

I upgraded my jQuery version to 1.4 from 1.3. My code worked fine in 1.3, but it doesn't in 1.4. What can I have done wrong?

function add_product_to_shopping_cart( product_id )
{
    $.post("/actions/etrade/add_product_to_cart",
    {
        'product_id': product_id,
        'variant_first': $('#main_variant-'+ product_id ).val(),
        'variant_secound': $('#secound_variant-'+ product_id ).val(),
        'stock': $('#stock-'+ product_id ).val()
    }, function(data) {
        if ( data.err == 0 )
        {
            $('#cart_count').html( data.item_count );
            $('#cart_price').html( data.cart_total_price );
            $('#cart_shop_more').fadeIn();
        }
        else
        {
            alert( data.err_msg );
        }

        alert('test');
    },"json");  
}

Thanks a lot all for helping me :)

+4  A: 

In jQuery 1.4+ your JSON has to be valid, it's a lot stricter about this. Check the server response you're getting in Firebug, Chrome, Fiddler, or any other tool and see if it's valid here: http://www.jsonlint.com/

If it's not, this is a server-side problem, make sure you're outputting valid JSON :)

Nick Craver
Hmmm its return this data for me, its right ( {err:1,err_msg: 'Du skal vælge en variant'} ) but i can take eg. data.err out in my function, its never com in, if i remove 'json' its work becures its send HTML back, but i need json, i load my API from a API domain eg. api.mydomain.com and i use it on testdomain.com eg.
NeoNmaN
@NeoNmaN - That's not valid JSON, my answer shows how to check it :) To be valid it must be double quoted, like this: `{ "err": 1, "err_msg": "Du skal vælge en variant" }`
Nick Craver
Tanks a lot, its work fine now, damm i hate thats kind of problems :)
NeoNmaN
@NeoNmaN - welcome :)
Nick Craver