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

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

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


文档里说了,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=

【热门文章】
【热门文章】