jquery ajax在Internet Explorer中不会触发 [英] jquery ajax doesnt trigger in Internet Explorer

查看:117
本文介绍了jquery ajax在Internet Explorer中不会触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在点击任何一组特定锚点时使用一个函数来触发。

这适用于Firefox 3和Chrome。

I am using a function to trigger when any of a particular set of anchors are clicked.
This works in Firefox 3 and Chrome.

当页面首次开始加载时它们不存在,因为它们是由XML + XSLT使用客户端转换创建的,以防万一这是相关的。

They don't exist when the page first starts loading as they are being created by XML+XSLT using client side transformation, just in case this is relevant some how.

我也只是把警报放在那里只是为了看看它是否做了什么......甚至在IE中都没有警报。它不适用于Chrome,但那是因为我错过了$ document.ready语句[仍然在FF中工作]但我不确定IE的缺失元素是什么。我使用IE 8顺便说一句。

I also only put that alert in there just to see if it was even doing anything... not even an alert in IE. It was not working in Chrome but that was because I was missing $document.ready statement [still worked in FF] but I am not sure what the missing element is for IE. I am using IE 8 btw.

        <script type="text/javascript">
        $(document).ready(function () {
            $("#BlogSelectList li a").click(function () {
                alert('hhi')
                var str = ($(this).attr("href")).slice(1, 37)
                $.ajax({
                    contentType: "application/json; charset=utf-8",
                    url: '../ws/WebServices.asmx/SetActiveBlog',
                    data: '{ActiveBlogID: "' + str + '"}',
                    dataType: 'json',
                    type: "post",
                    success: function (j) {
                            window.location.href = 'dashboard.aspx'
                    }

                });

            });
        })
    </script>


推荐答案

当锚点不在时,可能是相关的doc首先加载。您可以使用live方法快速修复。即使稍后将其添加到DOM,这也会将您的事件应用于您选择的任何事件。

It probably is relevant that the anchors are not there when the doc first loads. You could do a quick fix by using the live method. This will apply your event to whatever you're selecting even if it's added to the DOM later.

$("#BlogSelectList li a").live("click", function() {etc...});

此外,如果您使用锚点,则可能需要将href属性设置为 #这样它就不会触发浏览器在某处导航的默认行为。

Also, if you're using an anchor, you will probably need to set the href attribute to "#" so that it doesn't trigger the browser default behavior of navigating somewhere.

这篇关于jquery ajax在Internet Explorer中不会触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆