【发布时间】:2021-11-30 23:27:33
【问题描述】:
我在 asmx 页面中有一个 web 方法。我从 jquery Ajax 调用它。 只需 1 次即可正常工作,然后永远不会调用 web 方法。
[WebMethod(EnableSession = true)]
public static string WsCom(AjaxObjectsHelper.UpdatePageAjax Param)
{
try
{
if (HttpContext.Current.Session["AppName"] != null && HttpContext.Current.Session["USR"] != null)
{
string xRes = "";
if (Param.Action == "_GMH")
{
xRes = "";
}
else if (Param.Action == "_GMHL")
{
xRes = "";
}
else
{
xRes = SiteHelper.AjaxObjectsHelper.GetJson(new SiteHelper.AjaxObjectsHelper.ErrorAjax("Invalid Action.", false));
}
return xRes;
}
else
{
return SiteHelper.AjaxObjectsHelper.GetJson(new SiteHelper.AjaxObjectsHelper.ErrorAjax("Unauthorized access", false));
}
}
catch (Exception ex)
{
return SiteHelper.AjaxObjectsHelper.GetJson(new SiteHelper.AjaxObjectsHelper.ErrorAjax(ex.Message, false));
}
}
这里是我的 ajax 调用:
function (xF, xCB) {
var callData = { Param: { Action: "_GMH", Data: xF } }
$.ajax({
type: "POST",
url: "/mypage.asmx/WsCom"
data: JSON.stringify(callData),
contentType: "application/json; charset=utf-8",
dataType: "json",
cache: false,
success: function (response) {
console.log("success")
}
}).fail(function (jqXHR, textStatus, error) {
console.log(jqXHR.responseText);
});
}
每次调用ajax成功,而不是asp.net webmethod。 (它只是第一次断点) 任何想法?好像是缓存问题。
【问题讨论】:
-
可能是浏览器正在缓存数据。如果第一个响应,您可以检查过期标头吗?
-
第一次(当它工作时)缓存控制:无缓存过期:-1 调用缓存控制:私有,max-age=0 过期未显示