对 Java/Wicket 服务器的 jQuery AJAX 调用在 IE 中没有响应 (6/7/8)

发布于 2024-09-08 18:53:46 字数 1120 浏览 2 评论 0原文

注意:这与 上一个问题有关

我有一个 Wicket 页面,其中有一个包含一些复杂客户端交互的表单,我决定使用 jQuery 而不是 Wicket(我知道,讨论很长)。本质上,我只是构建一个 JSON 对象,通过 AJAX 提交它,并在完成时执行一些操作。该调用在 Firefox 中工作正常,但在任何版本的 IE 中都不起作用。我已经验证过没有多余的逗号。这是代码:

var lookup = {
    'name': name,
    'description': description,
    'items': [{
        'name': itemName,
        'value': itemValue
    }]
};

$.ajax({
    type: 'post',
    url: '${callbackURL}', // This file is parsed by Wicket and receives a dynamic callback URL here. This is not jQuery!
    cache: false,
    data: {'lookup': JSON.stringify(lookup)},
    contentType: 'application/json',
    complete: function() {
        alert('This never gets called in IE!')
    }
});

有什么建议吗?谢谢!

更新:看来我的问题是由于 IE 缓存资源造成的。我已经在 HTML 文件中放入了无缓存代码,但似乎该页面仍在被缓存(并且通过扩展,它引用了 JS),或者其中包含我的 jQuery 代码的 JS 文件正在被缓存其中包含旧的回调 URL,以便服务器不会响应,因为该 URL 上不再有任何内容。当我删除漂亮的 URL 时,一切正常(因为每次 Wicket 生成 URL 时,它都是唯一的)。尽管如此,即使没有服务器响应,也不应该调用 complete 函数吗?

Note: This relates to a previous question.

I have a Wicket page that has a form with some complex client-side interactions that I decided to use jQuery for instead of Wicket (long discussion, I know). Essentially I'm just building a JSON object, submitting it via AJAX, and performing some action on completion. The call works fine in Firefox, but not in any version of IE. I've already verified that there are no extraneous commas. Here's the code:

var lookup = {
    'name': name,
    'description': description,
    'items': [{
        'name': itemName,
        'value': itemValue
    }]
};

$.ajax({
    type: 'post',
    url: '${callbackURL}', // This file is parsed by Wicket and receives a dynamic callback URL here. This is not jQuery!
    cache: false,
    data: {'lookup': JSON.stringify(lookup)},
    contentType: 'application/json',
    complete: function() {
        alert('This never gets called in IE!')
    }
});

Any suggestions? Thanks!

Update: It appears my problem is due to IE caching the resources. I've put no-cache code in my HTML file, but it seems that either the page is still getting cached (and by extension, the JS it references), or the JS file with my jQuery code in it is being cached with the old callback URL in it so that the server doesn't respond because there's nothing at that URL anymore. When I remove the pretty URLs everything works fine (because every time Wicket generates the URL, it's unique). Still, shouldn't the complete function get called even if there's no server response?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

惜醉颜 2024-09-15 18:53:46

这是由于 IE 缓存过多造成的。通过向 URL 添加一个唯一生成的参数来解决这个问题,这样浏览器每次都会认为它是一个新的 URL。

This was due to aggressive IE caching. It was resolved by adding a uniquely generated parameter to the URL so the browser would think it's a new URL every time.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文