【发布时间】:2013-04-24 14:35:43
【问题描述】:
我有一个 jquery ajax POST 到代码隐藏网络方法。在那个 webmethod 中,我对返回 json 的第三方 web api 服务执行 HttpWebRequest。即使 httpwebrequest 工作正常,浏览器中也会出现一个弹出窗口,要求我输入凭据(需要身份验证)。在我的机器上这很好用,但是在部署时它不会,除非 httpwebrequest 调用没有返回数据。
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(
CacheDuration = 5,
EnableSession = true)]
public static string GetSomething(string user, string item)
{
// In the body i do the HTTPWebRequest that returns JSON
}
【问题讨论】:
-
如果您给我们一段代码,我们将不胜感激
标签: jquery ajax post httpwebrequest webmethod