0
我有一个jquery ajax POST代码隐藏webmethod。在那个webmethod我做了一个HttpWebRequest到第三方web api服务返回json。即使httpwebrequest工作正常,浏览器中会出现一个弹出窗口,要求我输入凭据(需要身份验证)。在我的机器上,这种方式运行良好,但是,如果没有从httpwebrequest调用返回的数据,它不会除外。jquery ajax调用失败,401未经授权
jQuery的电话:
function serverCall(httpMethod, pageName, methodName, inputData, successCallback, errorCallback, disableGlobalAjaxEvents) {
// Construct the url
var url = pageName + "/" + methodName;
var triggerGlobalEvents = true;
if (disableGlobalAjaxEvents && disableGlobalAjaxEvents == true) {
triggerGlobalEvents = false;
}
$.ajax({
type: httpMethod,
url: url,
data: JSON.stringify(inputData),
contentType: "application/json; charset=utf-8",
global: triggerGlobalEvents,
dataType: "json",
success: function(msg) {
if (successCallback) {
var parsedObject = JSON.parse(msg.d);
successCallback(parsedObject);
}
},
error: function(error, status) {
if (errorCallback) {
errorCallback(error, status);
}
}
});
这里是实际调用:
serverCall("POST", "SomePage.aspx", "GetSomething", inpuData, onSuccess, onError, true);
将WebMethod:
[WebMethod(
CacheDuration = 5,
EnableSession = true)]
public static string GetSomething(string user, string item)
{
// In the body i do the HTTPWebRequest that returns JSON
}
如果你给我们一段代码,将不胜感激 – Bhuvan 2013-04-24 14:51:14