送分題!首先的首先,涉及業務邏輯的輸入是需要透過引數傳遞的,主要有三種方法:path, query, POST/PUT bodypath: GET /api/user/123 其中的123透過path傳遞query: GET /api/search_user?userId=123body: POST /api/user-signup {username: "john"}不建議透過header傳參的原因:1. proxy 和 reverse proxy會drop header2. 不利於傳輸object3. HTTP access control (CORS) API 一般會設定Access-Control-Allow-Headers,分分鐘教你做人。4. 不利於dev和debug5. Header長度限制然後,如果你需要傳header,比如Authorization,如下。jQuery.ajax()headers (default: {})Type: PlainObjectAn object of additional header key/value pairs to send along with requests using the XMLHttpRequest transport. The header X-Requested-With: XMLHttpRequest is always added, but its default XMLHttpRequest value can be changed here. Values in the headers setting can also be overwritten from within the beforeSend function. (version added: 1.5)
送分題!首先的首先,涉及業務邏輯的輸入是需要透過引數傳遞的,主要有三種方法:path, query, POST/PUT bodypath: GET /api/user/123 其中的123透過path傳遞query: GET /api/search_user?userId=123body: POST /api/user-signup {username: "john"}不建議透過header傳參的原因:1. proxy 和 reverse proxy會drop header2. 不利於傳輸object3. HTTP access control (CORS) API 一般會設定Access-Control-Allow-Headers,分分鐘教你做人。4. 不利於dev和debug5. Header長度限制然後,如果你需要傳header,比如Authorization,如下。jQuery.ajax()headers (default: {})Type: PlainObjectAn object of additional header key/value pairs to send along with requests using the XMLHttpRequest transport. The header X-Requested-With: XMLHttpRequest is always added, but its default XMLHttpRequest value can be changed here. Values in the headers setting can also be overwritten from within the beforeSend function. (version added: 1.5)