如何在ASP.net MVC的Ajax加载页面上处理jQuery的事件? [英] How to handle jQuery event on an ASP.net MVC Ajax loaded page?

查看:122
本文介绍了如何在ASP.net MVC的Ajax加载页面上处理jQuery的事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题。

我在jQuery Mobile的世界的新手,并与ASP.Net MVC的一部分,我是有点失落。

I'm a newbie in the world of jQuery Mobile, and with the ASP.Net MVC part I'm a little bit lost.

下面是我的问题:在我的移动网站,我想改变导航栏(我使用更像是一个appbar)按钮,而我是一个编辑页面,或家庭等...

Here is my problem: In my mobile web site I want to change the navbar (that I use more like an appbar) buttons whereas I am on an Edit Page, or Home, etc....

因此​​,那些页面(编辑,显示)被装载在阿贾克斯,并在这些网页上,我想火象一个事件:

So those pages (Edit, Show) are loaded in ajax, and on these pages I'm trying to fire an event like :

$(document).ready(function(){
   alert("Hello !");
});

但有些期试验研究后,我发现,在JQM与阿贾克斯,事件不会按照这种方式,但更多的是这样的:

But after some researchs, i found that in JQM with Ajax, events doesn't work that way, but more like this :

$(document).bind('pageinit', function(){
   alert("Hello !");
});

但是,这并不为我工作(每个页面的变化是trigerred的情况下),可能是因为在ASP.Net MVC的手机,我们只有一个数据角色=页面和内容的其余部分被装载在阿贾克斯的数据角色=内容,所以我真的不知道我可以触发一个事件时,我的阿贾克斯加载类页被加载?

But this don't work for me (every page change the event is trigerred), maybe because in ASP.Net MVC Mobile we have only one data-role="page" and the rest of the content are loaded in ajax in the data-role="content", so I really don't know how I can fire an event when my "Ajax Loaded Kind of Page" is loaded ?

我曾试图住/绑定在这些页面中的一个的列表视图但是,这并不管用:

I had tried to live/bind on the listview of one of these pages but that does not work either :

$("[data-role='listview']").live('pageinit', function () {
    alert("hello");
});

要成为什么我想要做更多的precise: 在ASP.Net MVC的,我的布局(谁是他常见的我所有的网页)有一个 DIV 数据角色=页面属性。这个数据的作用是独特的,以我所有的应用程序,并且需要处理。 但事实是,当我在code加载其他ASP.Net MVC页:

< D​​IV数据角色=页面>
< D​​IV数据角色=内容>在这里,我的ASP.Net MVC页< / DIV>
< / DIV>

我无法使用的$(document).bind('pagenit'),因为我不加载一个页面(数据角色=页),但公正的一部分数据角色=内容

To be more precise about what i'm trying to do : In ASP.Net MVC, my layout (who his common to all my pages) has a div with a data-role="page"attribute. This data-role is unique to my all app, and need to deal with it. But the fact is, when I load an other ASP.Net MVC Page in my code :

<div data-role="page" >
<div data-role="content"> Here my ASP.Net MVC Page</div>
</div>

I cannot use the $(document).bind('pagenit') because i don' load a page (data-role=page) but just a part of a data-role="content".

如果您有任何想法,我将很高兴听到(更多阅读)吧,在此先感谢和抱歉,如果我的英语是不是真正的理解。

If you have any idea I will be glad to hear (more read) it, thanks in advance and sorry if my english is not really "understandable".

推荐答案

jQuery Mobile的获取视图通过AJAX和显示。由于这个原因,一般事件错过,因为它是一个AJAX调用

Jquery Mobile gets the view through the AJAX and displays it. Due to this, the general events miss out since it is an AJAX call.

最好的办法是禁用阿贾克斯每一个表,你需要提及每个重定向调用以及

The best option is to disable Ajax for every form, you need to mention on each redirection call as well

data_ajax =假

data_ajax = "false"

一旦成为常规通话,所有的jQuery的事件,正常工作!

Once it becomes a regular call, all Jquery events work normally!

这篇关于如何在ASP.net MVC的Ajax加载页面上处理jQuery的事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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