2012-03-15 38 views
2

我在使用Ajax授权标题时遇到了一些问题。我尝试这种方式发送:Ajax授权标题还未发送

$.ajax({ 
    url: query, 
    type: "GET", 
    accept: "application/json", 
    dataType: 'json', 
    beforeSend: function (xhr) { 
     alert('1'); 
     var bytes = Crypto.charenc.Binary.stringToBytes("xxxxxxxx:xxxxxxxxx"); 
     alert('2'+bytes); 
     var bas64 = Crypto.util.bytesToBase64(bytes); 
     alert('3'+bas64); 
     xhr.setRequestHeader("Authorization", "Basic " + bas64); 
     alert('up and awaaaaaaaay'); 
    }, 
    succes: function (result) { 
     alert('success!'); 
    }, 
    error: function (xhr, ajaxOptions, thrownError) { 
     alert(xhr.responseText); 
     //$('#DisplayInfoLoader').html('<span style="color: red;">An Error occured....' + xhr.responseText + '</span>'); 
     //$('#DisplayInfoLoader').fadeOut(3000); 
    } 
}); 

但是当我尝试个代码..它不会发送标题...用手去查询,网址和填写凭证工作...和即使凭证在会话中(/客户端GET请求完美地发送授权标头)访问/项目URI时不会发送标头....

+0

你使用的是什么版本的jQuery?你见过这个吗? http://forum.jquery.com/topic/please-confirm-setrequestheader-not-working – bububaba 2012-03-28 13:01:58

+0

那么我解决了我的问题,只是有语法错误,现在它为我工作...所以有人知道如何停止赏金?) )))))))) – 2012-03-28 13:09:27

+0

@DenisAgarev恐怕一旦它开始运行,赏金就是不可撤销的。好,但你解决了你的问题。 – blahdiblah 2012-03-28 19:29:23

回答

2

解决方案是标头不被服务所允许。浏览器删除服务不允许的每个标题。

确保该服务使用访问控制允许标题标题!这就是我所学到的