Tag: http status code 401

摆脱浏览器控制台中的401(未经授权)ajax错误

我正在使用jQuery.ajax调用通过javascript调用api。 如果用户未经过身份validation,则api会回复401,并且我只想为此调用忽略此错误。 我已经尝试了jQuery选项中描述的所有回调选项,但错误仍然在浏览器控制台中弹出(在Firefox和Chrome中)。 以下是触发错误的示例代码: $.ajax({ type: ‘GET’, url: ‘/url-with-auth’, dataType: ‘json’, statusCode: { 401: function (error) { // simply ignore this error console.log(error); } }, complete: logall, error: function () { // simply ignore this error console.log(error); }, async: false }).fail(function () { // ignore the error and do nothing else console.log(“$.get failed!”); }); 这还具有在由.htaccess文件保护的登台机上再次请求用户凭证的副作用,因为浏览器认为用户未被认证,因此在以下请求中用户需要重新输入他的http凭证。 […]

使用jquery调用webmethod一致地获得“401 Unauthorized”错误

我一直在努力让我的jquery调用webmethod工作。 我被服务器以“401 Unauthorized”响应退回。 我必须在web.config或其他阻止成功调用的地方设置不正确的设置。 非常感谢您的见解! 调用js函数调用jquery调用 button.OnClickAction = “PageMethod(‘TestWithParams’, [‘a’, ‘value’, ‘b’, 2], ‘AjaxSucceeded’, ‘AjaxFailed’); return false;”; 调用jquery的JavaScript函数 function PageMethod(fn, paramArray, successFn, errorFn) { var pagePath = window.location.pathname; var urlPath = pagePath + “/” + fn; //Create list of parameters in the form: //{“paramName1″:”paramValue1″,”paramName2″:”paramValue2″} var paramList = ”; if (paramArray.length > 0) { for (var […]

jquery $ .ajax调用在Chrome或Firefox中导致401未经授权的响应,但在IE中有效

我有一个在需要使用JQuery $ .ajax方法(当前使用jquery 1.7.2)的网页上运行的脚本,以向不同域上的服务端点提交几个GET请求。 我在IE(9,10,11)中使用了ajax调用,但它在Firefox和Chrome中失败了401 Unauthorized响应。 Chrome中的部分其他错误消息是“访问此资源需要完全身份validation”。 我的ajax调用设置如下(对于这些失败的请求,dataType为“json”,async为true): $.ajax({ url: url, type: “GET”, async: isAsync, dataType: dataType, username: user, password: pswd, success: function (response, status) { // success code here }, failure: function (response, status) { // failure code here }, complete: function (xhr, status) { // on complete code here } }); 我传递了访问该服务所需的用户名和密码,这在IE中有效。 我理解JQuery […]