passing credentials not working

℡╲_俬逩灬. 提交于 2019-12-06 09:56:56

问题


I am trying to make a json call, by passing the credentials. If the user is already logged into the system using Sql Membership, how can I pass the credentials without getting this:

Here is the code that calls the web.api:

NOTE: call is being made from cross domain: i.e. www.project.com -> api.project.com

var url = 'http://api.project.com/LookUps/uploadtypes?callback=?';

$.ajax({
    type: 'GET',
    url: url,
    async: true,
    xhrFields: {
        withCredentials: true
    },
    jsonpCallback: 'handler',
    contentType: "application/javascript",
    dataType: 'jsonp',
    success: function (json, textStatus, jqxhr) { console.log(jqxhr.responseText); },
    error: function (json, textStatus, jqxhr) { console.log(jqxhr.responseText); }
 });

Edit:

I still get the login when authentication is disabled. Is there another place for the window authentication setting?


回答1:


To prevent this popup you have to change your URL to following.

var url = 'http://username:password@api.project.com/LookUps/uploadtypes?callback=?';

replace username - with actual username and password with actual password.



来源:https://stackoverflow.com/questions/25767558/passing-credentials-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!