0

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 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.

4
  • 2
    What's the value of result.bgcolor if you console.log(result.bgcolor) Commented Dec 30, 2010 at 15:57
  • 2
    Does it work when you hardcode a color in place of result.bgcolor? Commented Dec 30, 2010 at 15:57
  • yeh it deos, i put '#ccc' and it worked. and the value of result.bgcolor 4d4947 Commented Dec 30, 2010 at 16:01
  • maybe its the string concantanation that im trying to put!!! Commented Dec 30, 2010 at 16:04

1 Answer 1

1

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

$.ajax({dataType: 'json'...})
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.