this is my code

 $('#Cancel').click(function() {

        var baseurl     = ' <?php echo $this->strBaseUrl?>';
        var cancel_msg  = " <?php echo Messageclass::setMessage('CAN01')?>";

        var where_to = confirm(cancel_msg);
        if (where_to == true){
            return true;
        }else{
            location.href = "";
        }

    });

but there is an error showing below the variable cancel_msg. the error is

Uncaught SyntaxError: Unexpected token ILLEGAL 

the php logic is working perfectly. if any one know about this please help me

thanks in advance

有帮助吗?

解决方案

It really depends on what setMessage outputs, but that error is referring to an illegal character. This could be a newline character but is more likely a double quote:

var cancel_msg = " <?php echo addslashes(Messageclass::setMessage('CAN01'))?>";

also, you could reduce your function to:

return window.confirm(cancel_msg);

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top