Agregue CSS a MySQL y luego utilícelo en jQuery .CSS (); función

I have stored this CSS in the DB:

{backgroundColor: "rgba(53, 162, 185, 0.3)", 
width: "800px",
bottom: "0px",
height: "7px",
left: "0px"}

This is the SQL Update:

UPDATE `conjure`.`conjurevariables` SET `setting` = '{\'backgroundColor\': \'rgba(53, 162, 185, 0.3)\', \'width\': \'800px\', \'bottom\': \'0px\', \'left\': \'0px\', \'height\': \'7px\'}' WHERE `conjurevariables`.`id` = 27

When I pull the CSS from the DB and add it to a variable and alert that variable this is what is returned:

{'backgroundColor': 'rgba(53, 162, 185, 0.3)', 'width': '800px', 'bottom': '0px', 'left': '0px', 'height': '7px'}

This seems like the correct information.

NEXT: If I add that variable into the CSS like: $('.something').CSS(variable);

No funciona.

HOWEVER: If I skip the step of pulling the data from the DB and just do this:

var variable = "{'backgroundColor': 'rgba(53, 162, 185, 0.3)', 'width': '800px', 'bottom': '0px', 'left': '0px', 'height': '7px'} ";

then call CSS like: $('.something').CSS(variable);


QUESTION: I must be missing something with the pulling the details from the database. When I look at the variable in looks truncated. But why would the alert show the correct information?

I also echoed the DB string into a [li] and when I look at that in firebug it also looks truncated. Please see picture below.

enter image description here

Notice the info is truncated.


preguntado el 01 de febrero de 12 a las 01:02

can you show us the jquery code you use for ajax request and css styling -

1 Respuestas

I think the way you are loading the variable, javascript things you are loading a string when you want an object. Convert the string to an object and load it into the css().

var obj = jQuery.parseJSON('{"background-color":"#00ff00"}');
alert( obj.background-color === "#00ff00" );


Respondido 01 Feb 12, 07:02

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.