Constants do not work in Javascript

Asked

Viewed 33 times

1

Good morning Guys, I don’t know if I’ll be clear, but I’m having a hard time here. I need to set the URL path in my Javascript.

define('URL', 'http://' . $_SERVER['HTTP_HOST'] . '/sistema/');
$html      = str_replace('#URL#'    ,URL            ,$html);

Define this constant, and it works in HTML and PHP perfectly. But in Javascript it looks like a String, I’ve tried several ways, and I believe it’s easy to solve, but I’m having a lot of difficulty. See the Javascript.

var url = '" . URL . "';

function criaAJAX() {
    if (window.XMLHttpRequest)
    {// Codigo para IE7+, Firefox, Chrome, Opera, Safari
        return new XMLHttpRequest();
    } else
    {// Codigo para IE6, IE5
        return new ActiveXObject("Microsoft.XMLHTTP");
    }
}

Thanks.

  • Forehead var url = '<?= URL?>';

  • Didn’t work, buddy.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.