gpt4 book ai didi

jQuery $.ajax 不在 IE 中调用 ASP.NET Web 服务方法

转载 作者:行者123 更新时间:2023-12-01 05:04:07 26 4
gpt4 key购买 nike

我一直在尝试像狄更斯那样通过 IE 使用 $.ajax 方法从 jQuery 调用 Web 服务,但它似乎不起作用。我浏览了 Stackoverflow 和大量的 Google 搜索,但人们提出的解决方案没有一个对我有用。

以下是设置方式...

jQuery 调用:

function PerformPainPointDataSubmit() {

var coordString = "";

var mapAreas = $('map[id$=body_profile_map]').find('area');

mapAreas.each(function() {
if ($(this).attr('shape').toLowerCase() == "circle") {
coordString += $(this).attr('coords') + ';';
}
});

$.ajax({
type: "POST",
url: "../../LandingPageWebService.asmx/PerformPainPointDataSubmit",
data: JSON.stringify({ "coords": coordString }),
//data: "{'coords':'" + coordString + "'}", // Doesn't work
//data: '{ "coords": "' + coordString + '" }' // Also doesn't work
contentType: "application/json; charset=utf-8",
datatype: "json",
async: true,
cache: false,
success: function(data) {
alert("success: " + status);
},
failure: function(msg) {
alert("fail: " + msg);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
debugger;
}
});
//$.delay(1000); <-- Explained a little further down
//return false;
}

请注意,successfailureerror 函数永远不会被调用。

以下是LandingPageWebService类的定义(一些数据库代码已被删除):

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class LandingPageWebService : System.Web.Services.WebService {

[WebMethod(EnableSession=true)]
public bool PerformPainPointDataSubmit(string coords)
{
string hotSpotCoords = string.Empty;

string[] coordsSplit = coords.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

// parse the string and make sure we only have
// values and nothing else.
foreach (string spl in coordsSplit)
{
string[] indCoords = spl.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

if (indCoords.Length != 3)
{
return false;
}
int x = 0;
int y = 0;

try
{
x = int.Parse(indCoords[0]);
y = int.Parse(indCoords[1]);

}
catch (FormatException formEx)
{
return false;
}

hotSpotCoords += x + "," + y + ";";
}
// snipped out Database saving code
return true;

}

jQuery 函数由 Button 内的 OnClientClick 调用:

<asp:Button ID="btnSave" Text="Save" runat="server" OnClientClick="PerformPainPointDataSubmit();CloseWin()" CssClass="STD_Button" ValidationGroup="vgEditClinicalSummary" CausesValidation="true" />

页面本身位于一个模式对话框中,单击“保存”按钮时该对话框会关闭。无论我调用多少次,Web 服务在 Chrome 和 Firefox 中调用都没有任何问题。然而对于 IE 来说,这一切就变得很糟糕了。

通常,但并非总是如此,它会在页面第一次加载时被调用。我认为存在缓存问题,但 cache:false 已经设置。我尝试在网址中添加 DateTime ,但我不断收到错误(老实说,我认为我的格式不正确,有建议吗?)。我尝试了不同的 datatype 字符串,当然 JSON.stringify() 可以工作,但就像我说的,它只能工作一次。

我注意到,当我在 jQuery 函数中出现中断时,如果我等待一两秒,IE 实际上会调用 Web 服务并成功执行。每次都会这样做。我认为模态窗口的关闭速度比服务器处理请求的速度快,并且无法进行 Web 服务调用。我在 jQuery 代码中添加了 $.delay(1000) 希望它能起作用,但不幸的是它没有。

现在我束手无策,完全不知道如何继续。一切似乎都合乎逻辑,但显然有些不对劲。

我将非常感谢任何人可以提供的帮助。

最佳答案

这听起来与此处描述的问题类似: Ajax request with JQuery on page unload

调用需要同步,以保证它在窗口关闭之前完成。

关于jQuery $.ajax 不在 IE 中调用 ASP.NET Web 服务方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7341492/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com