Hi im trying to get rest api data on html page by javascript fetch but i cant be able to fetch url categoryId can anyone help me out. Ill be so thank full of them.this is my Html page where i fetching my data
Asked
Active
Viewed 370 times
-1
-
Welcome to [so[. Please add code to the question as text rather than as pictures of code. – phuzi Dec 09 '21 at 10:33
-
Please read [ask]. – Quentin Dec 09 '21 at 10:35
-
Does this answer your question? [How can I do string interpolation in JavaScript?](https://stackoverflow.com/questions/1408289/how-can-i-do-string-interpolation-in-javascript) – phuzi Dec 09 '21 at 10:46
-
Please provide enough code so others can better understand or reproduce the problem. – Community Dec 15 '21 at 11:06
2 Answers
-1
What error do you get?
I guess you have categoryId
defined somewhere, so you should try something like this:
fetch(`/api/get_productc/${categoryId}`).then(...)
Be aware that there is a backtick around ( ` ) and $ sign before categoryId.

Dharman
- 30,962
- 25
- 85
- 135

Matej Mohar
- 37
- 7
-1
As im already fetch my data and in that data i have my catogeryId so i just take it out from that in this way onclick="productBrandDataById('+data[i].catogeryId+')">' Then i just fetch my data with this catogeryId like this fetch('/api/get_productc/'+catagoryId) then ill use it.

Taran Kapoor
- 1
- 2