The problem with the search.

html:

<form action="#" method="POST" class="navbar-search pull-right" id="searchValid"> <input type="text" id="search" name="search" class="search-query" placeholder="Поиск.."> <select name="nubexSelect" id="nubexSelect" size="1"> <option value="1">Имя</option> <option value="2">Фамилия</option> <option value="3">E-Mail</option> <option value="4">Дата регистрации</option> </select> <input type="submit" id="sbm" name="sbm" value="Найти"> </form> 

ajax:

 $('#searchValid').ajaxForm({ url: '/admin/users/search/search', dataType: 'text', success: function(data) { console.log(data); data = $.parseJSON(data); switch(data.status) { case 'error': $.jGrowl(data.error, { sticky: !1, position: "top-right", theme: "bg-red" }); $('input[type=sbm]').prop('disabled', false); break; case 'success': $.jGrowl(data.success, { sticky: !1, position: "top-right", theme: "bg-green" }); setTimeout("reload()", 1000); break; } }, beforeSubmit: function(arr, $form, options) { $('input[type=sbm]').prop('disabled', true); } }); 

search.php

 class searchController extends Controller { private $limit = 20; public function search($page = 1) { $this->document->setActiveSection('admin'); $this->document->setActiveItem('users'); if(!$this->user->isLogged()) { $this->session->data['error'] = "Вы не авторизированы!"; $this->response->redirect($this->config->url . 'account/login'); } if($this->user->getAccessLevel() < 2) { $this->session->data['error'] = "У вас нет доступа к данному разделу!"; $this->response->redirect($this->config->url); } $this->load->library('pagination'); $this->load->model('users'); $options = array( 'start' => ($page - 1) * $this->limit, 'limit' => $this->limit ); $total = $this->usersModel->getTotalUsers(); if($this->request->server['REQUEST_METHOD'] == 'POST') { $search = @$this->request->post['search']; $returnArray = array(); $row = 0; $query = mysql_query("SELECT * FROM users WHERE user_firstname LIKE '%ара%'");// %ара% — поставил пока просто для теста while($result = mysql_fetch_assoc($query)) { $returnArray[$row] = $result; $row++; } $users = $returnArray; } $paginationLib = new paginationLibrary(); $paginationLib->total = $total; $paginationLib->page = $page; $paginationLib->limit = $this->limit; $paginationLib->url = $this->config->url . 'adminls/users/search/search/{page}'; $pagination = $paginationLib->render(); $this->data['users'] = $users; $this->data['status'] = $status; $this->data['pagination'] = $pagination; $this->getChild(array('common/header', 'common/footer')); //return $this->load->view('admin/users/index', $this->data); //return json_encode($this->data); } } 
At the end of search.php there are such lines:

 //return $this->load->view('admin/users/index', $this->data); //return json_encode($this->data); 
If you uncomment the 1st line, then the console in the browser Uncaught SyntaxError: Unexpected token < in JSON at position 0 : Uncaught SyntaxError: Unexpected token < in JSON at position 0 If you uncomment the 2nd line, the console does not generate an error, but the html page does not load.

Tell me, please, how to figure it out?

  • And if you look in the network tab, in the content of responses to your ajax requests? In both cases. - Visman
  • @Visman, in both cases displays the sorted users. Only if return $this->load->view('admin/users/index', $this->data); it outputs as html, and if return json_encode($this->data); it just writes to the string. - Max.
  • one
    Tell me, what result and where do you expect? "html page does not load" And where should it be loaded? Ajax code implies that the response should be json. But there is no processing of this json - just the output of the request status by a pop-up message. Data.users contains data, but they are not interested in the code. If PHP has a html output option, then it would be worthwhile on the browser side to provide a container for results and load the html code there via $ .load () - AndryG

0