dongqin8652 2014-11-17 10:58
浏览 20
已采纳

如何通过ajax加载模态

I have a problem and i do not know how to describe it, I have index page with a lot of modal,now i do not include all modal when page would load, i want to load that modal by ajax when click their links, now i send a request to a controller by ajax and return renderPartial

return View::make('index.edit_language')
->with('languageinfo',LanguageInfo::where('user_id',$id)->get());

and ajax function

$.ajax({
    type: "POST", 
    url : "modal/lang",
    success : function (data) {  
        // alert('ok');
        $("#links").html(data); 
        $('#edit_lang_Modal').modal();
    }
 });

now every thing works good but when show that modal,js does not work!! it means when i click a link like this

<div class="mre_repeat_item lang_mre_repeat_item">
    <a href="#">add +</a>
</div>

<script type="text/javascript">
    $('#lang_mre_repeat_item').click(function() {
        alert('ok');
    });
</script>

it does not work. i hope you could understand me!!thanks

  • 写回答

1条回答 默认 最新

  • dongyong6045 2014-11-17 11:05
    关注

    Is it a selector issue? You define the div like this: add +

    And you register event listener like this:

    <script type="text/javascript">
        $('#lang_mre_repeat_item').click(function() {
            alert('ok');
        });
    </script>
    

    I assume it should be:

    <script type="text/javascript">
        $('.lang_mre_repeat_item').click(function(event) {
            event.preventDefault();
            event.stopImmediatePropagation();
            $.ajax({
                type: "POST", 
                url : "modal/lang",
                success : function (data) {  
                    // alert('ok');
                    $("#links").html(data); 
                    $('#edit_lang_Modal').modal();
                }
            });
        });
    </script>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决