[問題] JQ ajax使用curl

看板Ajax作者 (幽冥闇獄)時間10年前 (2015/01/14 13:27), 10年前編輯推噓0(005)
留言5則, 2人參與, 最新討論串1/1
各位大大,我從網站api看到用 HTTP Basic Auth 認證 他們提供的範例 curl "https://api.livechatinc.com/V2/agents" \ -u user:password \ -H X-API-Version:2 請問我要怎麼用 JQ ajax 自動認證,他都會一直要我打帳號密碼。 以下是我寫的 http://jsfiddle.net/18pz8era/ $.ajax({ type: "POST", url: 'https://api.livechatinc.com/V2/agents', dataType: "jsonp", success: function(msg){ alert(JSON.stringify(msg)); }, error: function() { alert("ERROR!!!"); } }); -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.252.197.246 ※ 文章網址: https://www.ptt.cc/bbs/Ajax/M.1421213279.A.5C4.html

01/14 14:17, , 1F
google => basic authentication
01/14 14:17, 1F
大大你好,我看網路上很多人都是這樣用,但是我加了沒有效果 beforeSend: function (xhr) { xhr.setRequestHeader('Authorization', "Basic " + btoa("user:password")); } ※ 編輯: hd92216 (111.252.197.246), 01/14/2015 16:52:10

01/15 02:23, , 2F
還有X-API-Version:2這Header啊 你當curl參數放好看的?
01/15 02:23, 2F

01/15 21:39, , 3F
請問該怎麼加呢? 實在不解...
01/15 21:39, 3F

01/16 01:41, , 4F
google => jQuery ajax add header
01/16 01:41, 4F

01/16 01:41, , 5F
關鍵字都有了還不會Google嗎
01/16 01:41, 5F
文章代碼(AID): #1KjVvVN4 (Ajax)
文章代碼(AID): #1KjVvVN4 (Ajax)