what should be the necessary 'routes setting' to successfully request a specific controller for ajax request in codeigniter?

Multi tool use
Multi tool use


what should be the necessary 'routes setting' to successfully request a specific controller for ajax request in codeigniter?



shows error 404 page not found, when send ajax request

Here is my codeigniter's routes file.


routes.php


$route['request_handler/search_service'] = 'Request_handler/search_service';
$route['(:any)'] = 'pages/view/$1';
$route['default_controller'] = 'pages/view';

$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;




Here is my jquery code for ajax request to a Request_handler controller


script.js


$(document).ready(function(){
$('#search_service').on('keyup', function(){
var request_url = "<?php echo base_url('request_handler/search_service');?>";
var ss = $('#search_service').val();
if (ss != '') {
$.ajax({
url:request_url,
method:"POST",
data: {search:ss},
dataType:"text",
success:function(data){
$('#search_result').html(data);
}
});
}
});
});




And this is my controller code

Request_handler.php


class Request_handler extends CI_Controller {

function __construct() {
parent::__construct();
$this->load->database();
}

public function search_service() {
$this->load->model('Model_request_handler');
$ss = $this->input->post('search');
return $this->Model_request_handler->search_services($ss);
}
}




I need to figure out why I am getting 404-Page Not Found error on ajax requests. Thanks in advance.





have you loaded your url helper in your controller? if not loaded in autoload.php and also tell all other url are working fine or not?
– pradeep
Jun 30 at 5:28



url


autoload.php





yes @pradeep I have already loaded in autoload.php. $autoload['helper'] = array('url', 'form', 'html');
– Dwarkesh Purohit
Jun 30 at 5:30





ok have u removed your index.php from the config.php? and what is the location of your .htaccess file?
– pradeep
Jun 30 at 5:33



index.php


config.php


.htaccess





yes I've removed it and the location for .htaccess file : ci_project_dir/application/{here is my .htaccess file resides}
– Dwarkesh Purohit
Jun 30 at 5:40





remove this $route['request_handler/search_service'] = 'Request_handler/search_service';
– AbdulAhmad Matin
Jun 30 at 6:12


$route['request_handler/search_service'] = 'Request_handler/search_service';




1 Answer
1



The route is unnecessary. Remove this


$route['request_handler/search_service'] = 'Request_handler/search_service';






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

jF2LwePLW0m,YpyWRIOa5 wbh6ObOiH,YP51aL8G2zh0yAZ
tsn40erbkoeTeTtzH8gIO4jy y Bj,5Qn,R5JPQQYhvd8e8rPNLLvgIDBy k3X5ie HS,UcYGrlP6cw3EkSz6

Popular posts from this blog

PySpark - SparkContext: Error initializing SparkContext File does not exist

django NoReverseMatch Exception

List of Kim Possible characters