英文:
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}`;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论