dtvnbe1428 2013-02-01 04:57
浏览 147
已采纳

Ajax加载重复整个页面

I am trying to refresh a div with jquery load(); but the load displays the correct information but duplicates entire parts of the page that arent in the div

$.ajax({
       type: 'POST',
       url: $(this).attr('action'),
       cache: false,
       data: $("#uses_form").serializeArray(),
       success: function(data)
       {
            $('#uses_form_div').load('#uses_form_div');

       }
     });
return false; });
  • 写回答

2条回答 默认 最新

  • doumi4974 2013-02-01 05:52
    关注

    i think you are having a misunderstanding..

    if you want to load an external url into the div block

    $('#uses_form_div').load("./a.file");
    

    will do it. see the api docs.

    Or if you are trying to load the ajax response of the $.ajax call into the div, it should be

    $.ajax({
           type: 'POST',
           url: $(this).attr('action'),
           cache: false,
           data: $("#uses_form").serializeArray(),
           success: function(data)
           {
                $('#uses_form_div').html(data); // see here
    
           }
    });
    

    UPDATED according to comments below:

    if the case of an included page to be refreshed. I have two ways to recommend.

    1. make the included file as a separate url and load it initially. so instead of include you will be loading it via jquery as the page loads by a jquery load call. and when you want to refresh it you can do $('#uses_form_div').load("./a.file");

    2. you can put it as include it self and when you need to update, make an ajx request get the data back. Here you have 2 choice. You can build the dom at server and give html as ajax response and simply $("#uses_form_div").html(data) or get the response as json and build your dom at client side and load it via same $("#uses_form_div").html(data).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器