[英]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/'我正在使用这个 API:'/api/categories/${catID}/items/addItem/'
from my spring boot java to enter some data to item table which has relation with category table.从我的spring boot java输入一些数据到与类别表有关系的项目表。
Now in javascript, I used ajax: $.ajax({ url: '/api/categories/${catID}/items/addItem/', type: "POST", contentType: "application/json", etc现在在javascript中,我使用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}现在我从 url 中得到一个问题,无法读取 ${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.这是真正的 API:“/api/categories/{categoryId}/items/addItem” 我查看了网站内部,但该解决方案对我不起作用。 Now how can I pass a value of a variable if the variable are in the middle.现在,如果变量在中间,我如何传递变量的值。
Thanks in advance.提前致谢。
您正在尝试使用需要反引号 (`) 而不是单引号 (') 的模板文字。
url: `/api/categories/${catID}/items/addItem/`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.