Domanda

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

È stato utile?

Soluzione

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);

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top