如何从JS向API URL传递参数

huangapple go评论67阅读模式
英文:

How to pass parameters to an API url from JS

问题

Hello, I have this API URL http://127.0.0.1:8000/api/outlay that brings default values. Now, I want to add filters to this URL. I tried to follow the example of Postman, which does it like this:

http://127.0.0.1:8000/api/outlay?startdate=2023-02-14&enddate=2023-02-15

This is what I tried, but it didn't work:

http://127.0.0.1:8000/api/outlay?startdate='startdateOutlay'&enddate='enddateOutlay'

The startdateOutlay and enddateOutlay are calendar inputs that change their values dynamically. Is it possible to do such a thing from JavaScript?

英文:

Hello i have this api url

http://127.0.0.1:8000/api/outlay

that brings default values now i want to add filters to this url i tried to follow the example of postman that does it like this:

http://127.0.0.1:8000/api/outlay?startdate=2023-02-14&enddate=2023-02-15

This is what i tried but didnt work:

http://127.0.0.1:8000/api/outlay?startdate='startdateOutlay'&enddate='enddateOutlay'

The startdateOutlay and enddateOutlay are calendar input that change value dynamically, is it possible to do such a thing from Javascript?

答案1

得分: 1

你可以使用模板字符串 ``

const apiUrl = `http://127.0.0.1:8000/api/outlay?startdate=${startdateOutlay}&enddate=${enddateOutlay}`;
英文:

You can use template string ``

const apiUrl = `http://127.0.0.1:8000/api/outlay?startdate=${startdateOutlay}&enddate=${enddateOutlay}`;

huangapple
  • 本文由 发表于 2023年2月27日 16:21:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/75578159.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定