Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/378.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Codeigniter&;Ajax-Console.log数据返回CI';s的HTML登录页_Javascript_Ajax_Codeigniter - Fatal编程技术网

Javascript Codeigniter&;Ajax-Console.log数据返回CI';s的HTML登录页

Javascript Codeigniter&;Ajax-Console.log数据返回CI';s的HTML登录页,javascript,ajax,codeigniter,Javascript,Ajax,Codeigniter,我想console.log使用ajax记录查询结果,但它以HTML代码输出CI登录页 JS: function getRouters(data) { $.ajax({ type: 'POST', url: "http://localhost/ldcm/Main_controller/getRouters", data: data, success: function (data) { console.log(data)

我想
console.log
使用ajax记录查询结果,但它以HTML代码输出CI登录页

JS:

 function getRouters(data)
  {
    $.ajax({
      type: 'POST',
      url: "http://localhost/ldcm/Main_controller/getRouters",
      data: data,
      success: function (data) {
        console.log(data);
      }
    });
  }

$('#generateRes').click(function () {
   var data = userDetailsObj.data.homesize.id + userDetailsObj.data.floors.id + userDetailsObj.data.internetPlan.id + userDetailsObj.data.devices.id;
   console.log(data);
   if(data) {
      getRouters(data);
   } else{

   }
});
public function getRouters(){
                $data = $_POST['data'];
                $this->load->model('Query_Model');
                $data = $this->Query_Model->getRouters($data);

                echo json_encode($data);
        }
public function getRouters($data)
        {
            $this->db->select('*');
            $this->db->where('id', $data);
            $q = $this->db->get('selection');
            $response = $q->result_array();
            return $response;
        }
控制器:

 function getRouters(data)
  {
    $.ajax({
      type: 'POST',
      url: "http://localhost/ldcm/Main_controller/getRouters",
      data: data,
      success: function (data) {
        console.log(data);
      }
    });
  }

$('#generateRes').click(function () {
   var data = userDetailsObj.data.homesize.id + userDetailsObj.data.floors.id + userDetailsObj.data.internetPlan.id + userDetailsObj.data.devices.id;
   console.log(data);
   if(data) {
      getRouters(data);
   } else{

   }
});
public function getRouters(){
                $data = $_POST['data'];
                $this->load->model('Query_Model');
                $data = $this->Query_Model->getRouters($data);

                echo json_encode($data);
        }
public function getRouters($data)
        {
            $this->db->select('*');
            $this->db->where('id', $data);
            $q = $this->db->get('selection');
            $response = $q->result_array();
            return $response;
        }
型号:

 function getRouters(data)
  {
    $.ajax({
      type: 'POST',
      url: "http://localhost/ldcm/Main_controller/getRouters",
      data: data,
      success: function (data) {
        console.log(data);
      }
    });
  }

$('#generateRes').click(function () {
   var data = userDetailsObj.data.homesize.id + userDetailsObj.data.floors.id + userDetailsObj.data.internetPlan.id + userDetailsObj.data.devices.id;
   console.log(data);
   if(data) {
      getRouters(data);
   } else{

   }
});
public function getRouters(){
                $data = $_POST['data'];
                $this->load->model('Query_Model');
                $data = $this->Query_Model->getRouters($data);

                echo json_encode($data);
        }
public function getRouters($data)
        {
            $this->db->select('*');
            $this->db->where('id', $data);
            $q = $this->db->get('selection');
            $response = $q->result_array();
            return $response;
        }
它应该那样打印吗?还是我在配置中遗漏了一个配置部分

试试这段代码

函数获取路由器(数据)
{
$.ajax({
键入:“POST”,
数据类型:“json”,
url:“http://localhost/ldcm/Main_controller/getRouters",
数据:数据,
成功:功能(数据){
控制台日志(数据);
}
});

}

我假设您的
.htaccess
代码不工作。其次,您需要更新控制器代码。更新以下代码:

.htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /ldcm/
    RewriteCond $1 !^(index\.php|resources|robots\.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L,QSA]

</IfModule>

正如您在评论中提到的,您得到的是errot
未识别索引:data
。这意味着在
POST
请求中未接收到
data
参数。验证您的
POST
请求您得到的信息。并替换
$data=$\u POST带有
$data=$\u POST['parameter']

在浏览器中直接点击URL
http://localhost/ldcm/Main_controller/getRouters
并检查您在响应中得到了什么。这会将我带回XAMPP仪表板。这意味着
URL
您的使用未
配置
存在
。现在试试
http://localhost/ldcm/index.php/main_controller/getrouters
现在显示未识别索引:数据我确实在根文件夹中添加了一个.htaccess文件,等等,我将编辑我的帖子并粘贴我的完整代码。添加数据类型后,我再也看不到页面,但也没有输出。首先,您尝试在
echo json\u encode中打印简单消息('message')
。如果是打印的,请检查控制器中的post数据是否正确。