I am using this API:’/api/categories/${catID}/items/addItem/’
from my spring boot java to enter some data to item table which has relation with category table.
Now in javascript, I used ajax:
$.ajax({
url: ‘/api/categories/${catID}/items/addItem/’,
type: “POST”,
contentType: “application/json”,
etc
Now I get a problem from the url and cannot read the value of ${catID}
This is the real API: “/api/categories/{categoryId}/items/addItem”
I have looked inside the site but the solution does not work with me.
Now how can I pass a value of a variable if the variable are in the middle.
Thanks in advance.
You’re trying to use template literals which require backticks(`) instead of single quotes(‘).
url: `/api/categories/${catID}/items/addItem/`
Tags: ajax, java, javascriptjavascript, url