前端进行API调用时,如何使用apikey。

图片描述

如图,已有apikey和地址。用jquery的ajax写,不知道如何添加apikey,所以一直提示missins apikey.
网上也找了很久,没有这方面的资料。

图片描述

阅读 11k
4 个回答

文档里说了,apikey作为请求参数是放在header里传递的。
使用jquery的话可以查看官方文档添加header的方法:

$.ajax({
    url: '..',
    headers: {
        apikey: 'xxxx'
    }
})

headers (default: {})
Type: PlainObject
An 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)

而ip参数则正常地放在url Param里传递

http://api.jquery.com/jquery.ajax/

data
Type: PlainObject or String or Array
Data to be sent to the
server. It is converted to a query string, if not already a string.
It's appended to the url for GET-requests. See processData option to
prevent this automatic processing. Object must be Key/Value pairs. If
value is an Array, jQuery serializes multiple values with same key
based on the value of the traditional setting (described below).

新手上路,请多包涵

在请求地址后面加上参数:
url?apikey=&ip=

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题