【问题标题】:CodeIgniter : How to retrieve ajax jquery data passed through window.location.href in new controllerCodeIgniter:如何在新控制器中检索通过 window.location.href 传递的 ajax jquery 数据
【发布时间】:2015-08-13 07:19:37
【问题描述】:

CodeIgniter:如何在新控制器中检索通过window.location.href 传递的ajax jquery 数据?

$(".x").on("click","a.p",function(){       
            productId =  $(this).attr("productId");        
            alert("product ID : " + productId); 
            $.ajax({
               url: 'home/allProductDetails',
               type: 'POST',
               data: {
                 'productId'  : productId
               },
               success: function (dat) {

                    var result = eval('(' + dat + ')');
                    if (result.success == true)
                    {   
                        if(result.data.length>0)
                        {//alert("Success");window.location.href = "newControllerName" + "?result=" + result.data;
                         }
                    }

在 ajax 成功时,使用 window.location.href 将数据传递给新控制器

【问题讨论】:

  • 如何在 PHP 中使用。 $_GET['result']
  • 我想你当你想要检索/获取数据时总是使用 GET 方法
  • 谢谢纳伦德拉和奥尔德林27
  • 如何拆分通过 $_GET['result'] 检索到的数组数据
  • 在检索数组数据时,得到的结果为 x,y,z,a,b,c,l,m,n 而不是 x,y,z(第一个数组); a,b,c(第二个数组)和 l,m,n(第三个数组)

标签: php jquery ajax codeigniter controller


【解决方案1】:

试试这个,

阿贾克斯:

$(".x").on("click","a.p",function(){       
   productId =  $(this).attr("productId");        
   alert("product ID : " + productId); 
   $.ajax({
      url: 'home/allProductDetails',
      type: 'POST',
      data: {
        'productId'  : productId
      },
      success: function (dat) {

         var result = eval('(' + dat + ')');
         if (result.success == true)
         {   
            if(result.data.length>0)
            {
               //alert("Success");
               window.location.href = "newControllerName/methodName/" + result.data;
            }
         }
   });
});

控制器:

function methodName($data)
{
    //here you can access `$data` variable   
    print_r($data); 
}

这个可以试试...

【讨论】:

  • newControllerName中默认访问index函数。那么我们如何发送数据
  • 数据不能通过附加'/'来传递
  • / 将 next thing 作为方法,然后将 next 作为参数,所以请检查我的更新答案.....
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-04-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多