开发者

changing css properties through ajax, does not work?

开发者 https://www.devze.com 2023-02-02 07:27 出处:网络
I\'m trying to change the background color of a div, by using ajax (to retrieve the user\'s color from the database). Here is the code:

I'm trying to change the background color of a div, by using ajax (to retrieve the user's color from the database). Here is the code:

$.ajax({type: "POST", data: {id: id}, url: "actions/css.php", success: function(result) {
    $('.panel').animate({left: 350, width:700});
    $('.data').html(id);
       //background color
    $('.panel').css('background-color','#' + result.bgcolor);
});

But the color doesn't change, I know the JSON has been retrieved开发者_JAVA百科 by checking firebug, but it looks like a client side thing.

EDIT:

 $('#mainTitle').html(result.title);

If this doesn't seem to work, I guess it might be JSON compatibility or something.


On your $.ajax call you should specify the the dataType to json

$.ajax({dataType: 'json'...})
0

精彩评论

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