javascripteval.post

eval is not working with variable


my problem is eval with variable. I am using $.post this is so good for me. And returning

$(#172161616).css("color",'blue'); or $(#172161616).css("color",'red');

this is working i can return this but, how can i run this code in function response.

$.post("switch-up-control.php", {
        ip: ip,
        id: sw_id
    }, function(response){
         eval(response);        //i want run code here.
    });

error is : Uncaught SyntaxError: Unexpected token ILLEGAL

Thanks all.


Solution

  • What you're trying to do seems like a bad idea, but you're getting an error because the code is invalid. There are no quotes around the selectors:

    $(#172161616).css("color",'blue');
    

    this should probably be:

    $("#172161616").css("color",'blue');