I have a config.js
:
function get_config() {
var domain = "www.example.net";
var base_url = domain + '/includes/api.php';
return {
domain: domain, // domain
base_url: base_url,
}
}
When I use it:
<script>
function login() {
console.log("log in");
var configs = get_config()
var base_url = configs.base_url;
console.log(base_url); // there output: `www.example.net/includes/api.php`
var opt = {
action: "ValidateLogin",
email: $("#login_email").text(),
password2: $("#login_password").text(),
responsetype: 'json'
}
$.ajax({
type: "post",
url: base_url,
dataType : "json",
//contentType : "application/json",
data: opt, // JSON.stringify(opt)
success: function (data) {
console.log(data);
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(jqXHR, textStatus, errorThrown);
}
});
}
</script>
You see I use the base_url
:
but there get error when I run the login()
function:
Request URL: http://localhost:63342/template/www.example.net/includes/api.php
Request Method: POST
Status Code: 404 Not Found
Remote Address: 127.0.0.1:63342
Referrer Policy: no-referrer-when-downgrade
You see there added the additional prefix http://localhost:63342/template/
. why?
I run the project with WebStorm.