JQuery的远程API通过HTTP基本认证头 [英] JQuery Remote API With HTTP Basic Authentication Header

查看:223
本文介绍了JQuery的远程API通过HTTP基本认证头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们都绑做出了MYEMMA API的连接必须包括包含公共和放大器的HTTP基本认证头;私有API密钥我们的帐户。

We are tying to make a connection to the MYEMMA API which must include an HTTP Basic authentication header containing the public & private API keys for our account.

我们如何纳入我们的jQuery API调用这些信息?下面是我们到目前为止有:

How do we include this information in our JQuery API call? Here is what we have so far:

<script type="text/javascript">
  $(document).ready(function() {
    url:  "https://api.e2ma.net/123/members/add",
    dataType: 'json',
    type: "POST"
     {
       "fields": {
       "first_name": "Benjamin"
     },
     "email": "benjamin@myemma.com"
    }
  });
</script>

我们只需要知道如何创建认证头,包括我们的钥匙,在调用包含。

We just need to know how to create the authentication header, including our keys, to include in the call.

有关参考: http://myemma.com/api-docs/

推荐答案

什么您正在做的是从很远是你应该做的(它看起来像你给标签,以大量的字符串,等等,不能以逗号分开的,这将是一个的标签无效的错误)。

What you are currently doing is very far from what you should be doing (it looks like you are giving labels to lots of strings, etc, which cannot be comma separated, which will be an invalid label error).

由于按照文档,添加用户名密码键,您的 $。阿贾克斯()

As per the docs, add username and password keys to your $.ajax().

$.ajax({
    username: 'username',
    password: 'password',
    url:  'https://api.e2ma.net/123/members/add',
    dataType: 'json',
    type: 'POST',
    data: {
       first_name: 'Benjamin',
       email: 'benjamin@myemma.com'
    }
});

您不需要等待DOM要准备好火XHR。

You don't need to wait for the DOM to be ready to fire a XHR.

这篇关于JQuery的远程API通过HTTP基本认证头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆