Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何通过在javascript中连接两个字符串来获取url字符串_Javascript_Axios - Fatal编程技术网

如何通过在javascript中连接两个字符串来获取url字符串

如何通过在javascript中连接两个字符串来获取url字符串,javascript,axios,Javascript,Axios,我正在尝试使用axios发送请求,当我硬编码url时,效果很好,如下所示: const logIn = (email, password) => { axios.post("http://127.0.0.1:8000/api/token_auth/", { username: email, password: password }) .then(function (Response) { console.log('Login succesfull');

我正在尝试使用axios发送请求,当我硬编码url时,效果很好,如下所示:

const logIn = (email, password) => {
  axios.post("http://127.0.0.1:8000/api/token_auth/", {
    username: email,
    password: password
  })
  .then(function (Response) {
    console.log('Login succesfull');
  })
  .catch(function (Error) {
    console.log('Login failed.');
  });
}
import apiServer from 'controllers/settings';

const logIn = (email, password) => {
  axios.post(apiServer+"token_auth/", {
    username: email,
    password: password
  })
  .then(function (Response) {
    console.log('Login succesfull');
  })
  .catch(function (Error) {
    console.log('Login failed.');
  });
}
问题是当我尝试连接两个字符串以获得相同的url时,如下所示:

const logIn = (email, password) => {
  axios.post("http://127.0.0.1:8000/api/token_auth/", {
    username: email,
    password: password
  })
  .then(function (Response) {
    console.log('Login succesfull');
  })
  .catch(function (Error) {
    console.log('Login failed.');
  });
}
import apiServer from 'controllers/settings';

const logIn = (email, password) => {
  axios.post(apiServer+"token_auth/", {
    username: email,
    password: password
  })
  .then(function (Response) {
    console.log('Login succesfull');
  })
  .catch(function (Error) {
    console.log('Login failed.');
  });
}
在后面的例子中,我可以看到连接没有直接工作,因此我没有得到我要查找的url字符串:

javascript中是否有其他方法连接两个字符串,以便将结果字符串用作url

编辑

apiServer的值在另一个文件
settings.js
中定义:

const apiServer = "http://127.0.0.1:8000/api/"; 

由于某种原因,
apiServer
似乎是一个对象

只需确保它是一个字符串,然后您就可以按如下方式进行串联或字符串插值:

const apiServer=”http://127.0.0.1:8000/api/"
常量url=`${apiServer}令牌\u身份验证`

console.log(url)
您应该导出settings.js文件中的常量:

export const apiServer = "http://127.0.0.1:8000/api/";

apiServer
显然是一个对象。你需要一个字符串。你能告诉我们如何构建
apiServer
?@misterjojojo@misterjojojo axios实际上是什么,如果有的话,与不正确的字符串连接关系很小,并且与
apiServer
@HuLuViCa的值完全相关。那么,你在哪里定义它呢?您应该提供实际的代码