I have a PHP config document with these line
config.php:
define("BASE_URL","http://192.168.1.1");
But I'm need these in JS/JQuery. How can i do this?
Maybe I will have to create a JS config file too?
Once you have the baseurl variable in your html files, you can then use it for other loading your js scripts and ajax request. Like so:
<script>
var base_url = "<?php echo BASE_URL;?>";
</script>
//load css
<link rel="stylesheet" type="text/css" href="<?php echo BASE_URL;?>css/bootstrap.min.css">
//load jquery
<script type="text/javascript" src="<?php echo BASE_URL;?>js/jquery.min.js"></script>
//use js variable base_url for ajax request too
$.ajax({
url:base_url+"your-url-here",
type: "POST",
data: params,
dataType: "json"
})
.done(function(res){
//do something here
})
.fail(function(xhr, textStatus){
console.log("Got error.");
return;
})