简体   繁体   English

Rest API Ajax调用将参数添加到URL

[英]Rest API Ajax Call Add parameter to URL

Mostly, rest api url' s like: 通常,其余api网址如下:

/api/student:id/notes

I create a rest api and my urls like above. 我创建了一个REST API和上面的网址。 But I dont know how to add parameter before notes. 但我不知道如何在注释前添加参数。

$.ajax({
    url : "api/v1/student/notes",
    data : { "id" : uid },
    type : "get",
    headers : { "Authorization" : api_key },
    dataType : "json",
    success : function(response) {
        console.log(response);
    }
});

When I call like this, the url seems /api/student/notes?id=5 . 当我这样打电话时,网址似乎是/api/student/notes?id=5 How can Iadd id parameter between student and notes? 如何在学生和笔记之间添加id参数?

Example url: http://www.sitepoint.com/best-practices-rest-api-scratch-introduction/ 网址示例: http : //www.sitepoint.com/best-practices-rest-api-scratch-introduction/

AFAIK, jQuery does not offer a neat API for injecting resource URI fragments like Angular's $resource . AFAIK,jQuery没有提供整齐的API来注入资源URI片段,例如Angular的$resource You'll have to build the URL yourself. 您必须自己构建URL。 Something like 就像是

$.ajax({
    url: 'api/v1/students/' + encodeURIComponent(uid) + '/notes',
    // and so on, no "data" required.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM