English 中文(简体)
JQuery 的交叉站点 HTTP 认证
原标题:Cross site HTTP authentication in JQuery

我想看看是否可以登录到使用 HTTP 认证的第三个网站。 理想的情况是, 浏览器会保存证书。 但不幸的是, 每次都失败了。 任何帮助都会非常感激, 我都会使用我测试过的 Base64 Jquery 插件。

所以,有两个问题:

  1. How can I view the HTTP status code?
  2. Will this ultimately work, in principle?

<script>
$("#login_button").click(function() {   
        var username =  myFunUsername ;
        var password =  myFunPassword ;

        $.ajax({
                url:  http://remote-site-with-http-auth.com/member_site ,
                beforeSend: function(xhr) {
                        xhr.setRequestHeader("Authorization", "Basic " + $.base64.encode(username + ":" + password));
                },
                success: function(data) { $("#label").text("Logged in, yay!"); }
        }).fail(function(){ $("#label").text("It didn t work"); });

});

谢谢!

最佳回答
var user=  myFunUsername ;
var pwd=  myFunPassword ;
        $.ajax({
                url:  http://remote-site-with-http-auth.com/member_site ,
                crossDomain:true,
                username :user,// Keep the variable name different from parameter name to avoid confusion
                password:pwd,
                xhrFields: { /* YOUR XHR PARAMETERS HERE */}

                beforeSend: function(xhr) {
                       // Set your headers
                },
                success: function(data, textStatus, xhr) {
                    alert(xhr.status);// The status code
                    //Code for success
                }
        }).fail(function(){ 
               //Fail code here
               });

有关参数的更多详情,请查阅http://api.jquery.com/jQuery.ajax/

问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签