javascript - Refresh conent with JQueryAJAX after using a MVC partial view - Stack Overflow

Using the following JQueryAJAX function I'm calling a partial view when an option is changed in a

Using the following JQuery/AJAX function I'm calling a partial view when an option is changed in a bobox named "ReportedIssue" that is also in the partial view. The is named "tableContent".

<script type="text/javascript">
    $(function() {
        $('#ReportedIssue')
      .change(function() {
          var styleValue = $(this).val();
          $('#tableContent').load(
          '/CurReport/TableResults',
          { style: styleValue }
        );
      })
      .change();
    });
</script>

My problem is that after the jump to the partial view I lose the link to the javascript. I think I'm supposed to use the JQuery ".live()" but I'm unsure.

In short, I want to re-establish the link between my JavaScript and my bobox and after the inclusion of the partial view's HTML.

I hope I'm being clear enough,

Aaron

Using the following JQuery/AJAX function I'm calling a partial view when an option is changed in a bobox named "ReportedIssue" that is also in the partial view. The is named "tableContent".

<script type="text/javascript">
    $(function() {
        $('#ReportedIssue')
      .change(function() {
          var styleValue = $(this).val();
          $('#tableContent').load(
          '/CurReport/TableResults',
          { style: styleValue }
        );
      })
      .change();
    });
</script>

My problem is that after the jump to the partial view I lose the link to the javascript. I think I'm supposed to use the JQuery ".live()" but I'm unsure.

In short, I want to re-establish the link between my JavaScript and my bobox and after the inclusion of the partial view's HTML.

I hope I'm being clear enough,

Aaron

Share Improve this question asked Mar 23, 2010 at 21:32 Aaron SalazarAaron Salazar 4,53710 gold badges43 silver badges55 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 2

This answer is deprecated, see Mike's answer


As of jQuery 1.4 you can use the live handler with the change event. Simply change your code to work with it. If you are stuck with an earlier version of jQuery, you need to reapply the handler in the AJAX callback.

$(function() { 
    $('#ReportedIssue').live('change', function() { 
      var styleValue = $(this).val(); 
      $('#tableContent').load( 
          '/CurReport/TableResults', 
           { style: styleValue } 
      ); 
    })
});

Since .live() is now deprecated. Use .on(). Or, in my success callback, I simply did a .load() $('#container').load('index.php', '#right'); Worked like a charm.

Yes you should use live():

$('#ReportedIssue').live('click', function() {

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745362296a4624415.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信