duandao2306 2013-11-13 18:33
浏览 27

从索引到加载的div文件的jquery

Ok so the title is a little odd but wasn't sure how to describe problem in 1 line (feel free to update it) so I'll explain the best I can.

I load content from a file foobar.php into a div #foobar in index.php like so:

$('.foo').click(function(){
       var id = $(this).attr('id'),
          cls = $(this).attr('class'),
         dstr = 'id='+id;

        if(cls=='bar'){

          $.ajax({
             type:'GET',
              url:'foobar.php',
             data:dstr,
            cache:false,
          success:function(a){
       // this is where it calls for the content of foobar.php 
            $('#foobar').html(a);
      }}
     )
    }
  return false;
});

in foobar.php it queries database and shows the results depending on unique id which works fine, but it also has a form which I'm trying to use with jquery.form.

Now if I add the script links in foobar.php it works great:

<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="jquery.form.min.js"></script>

but these jquery files are are loaded in index.php so am wanting if possible to get jquery.form to work using the already loaded jquery files from index.php.

I know it doesn't currently work as it has something to do with the fact the content of foobar.php is being loaded into/via a dom and so as the lines above are not present in foobar.php it can't call them?!

  • 写回答

1条回答 默认 最新

  • dtxpz8785 2013-11-13 18:49
    关注

    You will have to call this (with your form selector instead of "#myForm") after you have loaded the page within the success function.

    $('#myForm').ajaxForm(function() { 
        alert("Thank you for your comment!"); 
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥20 iqoo11 如何下载安装工程模式
  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?