簡體   English   中英

Rest API Ajax調用將參數添加到URL

[英]Rest API Ajax Call Add parameter to URL

通常,其余api網址如下:

/api/student:id/notes

我創建了一個REST API和上面的網址。 但我不知道如何在注釋前添加參數。

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

當我這樣打電話時,網址似乎是/api/student/notes?id=5 如何在學生和筆記之間添加id參數?

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

AFAIK,jQuery沒有提供整齊的API來注入資源URI片段,例如Angular的$resource 您必須自己構建URL。 就像是

$.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