【问题标题】:jquery ajax post not working with .load in codeigniterjquery ajax post在codeigniter中无法使用.load
【发布时间】:2011-05-29 12:35:07
【问题描述】:

我希望使用 jquery ajax 加载多个视图结果

原代码(js)

$(document).ready(function(){
$("#uid").change(

function(){

    var uid=$("#uid").val();

    $.ajax({
    type: "POST",
    url: "<?= site_url('sp_profile/ajax_userdetail') ?>",
    dataType: "json",
    data: "uid="+uid,
    cache:false,
    success:
      function(data){

        $("#content").html(data);
      }

    });

  return false;

});
});

这在&lt;div id="content"&gt;&lt;/div&gt; 中只返回一个结果

如果我想加载 3 个结果,如

<div id="content"></div> 
<div id="content1"></div> 
<div id="content2"></div> 
  • 内容可以是用户 ID
  • content2 可以是用户名
  • content3 可以是用户姓氏

我的 js 应该使用 .load 而不是 html 对吗?如果我错了,请告诉我。

success:
          function(data){

            $("#content").load("<?= site_url('sp_profile/ajax_userdetail')?>");
            $("#content2").load("<?= site_url('sp_profile/ajax_userdetail')?>");
            $("#content3").load("<?= site_url('sp_profile/ajax_userdetail')?>");
          }

我整天都在坚持这件事..

请任何人告诉我执行控制器和 js 代码的正确方法。

【问题讨论】:

    标签: jquery ajax codeigniter load


    【解决方案1】:

    我在这里猜测,自己使用load,而不是在success方法中。

    比如说……

    $(document).ready(function(){
      $("#content").load("<?= site_url('sp_profile/ajax_userdetail')?>");
      $("#content2").load("<?= site_url('sp_profile/ajax_userdetail')?>");
      $("#content3").load("<?= site_url('sp_profile/ajax_userdetail')?>");
    });
    

    见this link。请记住,加载是 GET 而不是 POST。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-30
      • 1970-01-01
      • 1970-01-01
      • 2014-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多