Basic Authentication with jQuery.ajax request and jsonp

I have some local html/js files with which I'd like to invoke some remote servers via https and eventually use Basic Authentication for the request. I am encountering two problems. First is that if I don't specify 'jsonp' for the dataType, jQuery.ajax() request returns the error: > Access to restricted URI denied code: > 1012 Are my requests considered cross-domain because my main work file is stored locally, but retrieving data from a server elsewhere? So fine, I update the call so it now looks like: $.ajax({ url: myServerUrl, type: "GET", dataType: "jsonp", // considered a cross domain Ajax request if not specified username: myUsername, password: myPassword, success: function(result) { // success handling }, error: function(req, status, errThrown){ // error handling } }) Because I need to use Basic Authentication, I'm passing in the username/password but if I monitor the request, I don't see it being set and additionally, the server sends an error response since it doesn't have the expected info. Additionally, because I have `jsonp` set, `beforeSend` won't get invoked. How do I pass along the credentials using Basic Authentication for this request?

以上就是Basic Authentication with jQuery.ajax request and jsonp的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准