WhiteFlower
WhiteFlower

Reputation: 73

how can I send a data by ajax and the url has a variable value in the middle of the link

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.

Upvotes: 0

Views: 349

Answers (1)

Steve Barakat
Steve Barakat

Reputation: 327

You're trying to use template literals which require backticks(`) instead of single quotes(').

url: `/api/categories/${catID}/items/addItem/`

Upvotes: 4

Related Questions