post / get后jQuery双事件触发

时间:2021-02-03 20:35:51

ok i've wracked my brain and others to figure out why this is happening in IE and latest version of FF. It works in chrome. i am but a novice developer and recently started using jquery. so i dont even know if i'm going about this correctly.

好吧,我已经破坏了我的大脑和其他人,弄清楚为什么在IE和最新版本的FF中发生这种情况。它适用于chrome。我只是一个新手开发人员,最近开始使用jquery。所以我甚至不知道我是否正确地这样做。

its a basic form for the most part. jquery ajax post() then get() to update the page. once the page is loaded from get, the right hand nav/sidebar collapsible headings double fire and so do the action links in the action pane. i've tried binding the click event with bind(), live(), and delegate(). it worked originally with bind but i had to rebind all my click events after the ajax call and i am trying to find a way around that.

它大部分是基本形式。 jquery ajax post()然后get()更新页面。一旦从get加载页面,右侧导航/侧栏可折叠标题会双击,操作窗格中的操作链接也会加倍。我尝试使用bind(),live()和delegate()绑定click事件。它最初使用bind工作,但我不得不在ajax调用后重新绑定我的所有点击事件,我试图找到解决方法。

i've set up a static version of the app that i'm building here:

我已经设置了我正在这里构建的应用程序的静态版本:

http://ishiftdelete.com/pw_mkvi/ajax_wtf.htm

http://ishiftdelete.com/pw_mkvi/ajax_wtf.htm

to test: click on the Edit Page link inside the actions page in the right-hand nav/sidebar. this will open a model dialog with a form and submit button.

测试:单击右侧导航/侧栏中操作页面内的编辑页面链接。这将打开一个带有表单和提交按钮的模型对话框。

2 个解决方案

#1


1  

Ok so a friend of mine figured this out. Apparently scripts were being loaded twice.

好的,我的一个朋友想出来了。显然脚本被加载了两次。

BAD:

坏:

$.get(gurl, function (data) {
    var $response = $('<div />').html(data);
$('#mydiv').html($response.find('#mydiv').html()); //form
});

GOOD:

好:

$.get(gurl, function (data) {
    var $response = $(data);
$('#mydiv').html($response.find('#mydiv').html()); //form
});

#2


0  

I know you've already solved this, but for future finders, you can add a wrapper around your <div> like this:

我知道你已经解决了这个问题,但是对于未来的发现者,你可以在你的

周围添加一个包装器,如下所示:

<div id="myDivParent">
  <div id="myDiv"></div>
</div>

Then you can simplify your situation with .load() and the element you're looking for, like this:

然后,您可以使用.load()和您正在寻找的元素来简化您的情况,如下所示:

$("#myDivParent").load(gurl + " #myDiv");

That's it, if you pass the argument as url selector it'll get only that element from the response :)

就是这样,如果你将参数作为url选择器传递,它将只从响应中获取该元素:)

#1


1  

Ok so a friend of mine figured this out. Apparently scripts were being loaded twice.

好的,我的一个朋友想出来了。显然脚本被加载了两次。

BAD:

坏:

$.get(gurl, function (data) {
    var $response = $('<div />').html(data);
$('#mydiv').html($response.find('#mydiv').html()); //form
});

GOOD:

好:

$.get(gurl, function (data) {
    var $response = $(data);
$('#mydiv').html($response.find('#mydiv').html()); //form
});

#2


0  

I know you've already solved this, but for future finders, you can add a wrapper around your <div> like this:

我知道你已经解决了这个问题,但是对于未来的发现者,你可以在你的

周围添加一个包装器,如下所示:

<div id="myDivParent">
  <div id="myDiv"></div>
</div>

Then you can simplify your situation with .load() and the element you're looking for, like this:

然后,您可以使用.load()和您正在寻找的元素来简化您的情况,如下所示:

$("#myDivParent").load(gurl + " #myDiv");

That's it, if you pass the argument as url selector it'll get only that element from the response :)

就是这样,如果你将参数作为url选择器传递,它将只从响应中获取该元素:)