i used typeahead in my codeigniter 3 project and it worked well on localhost but when i ran it on live server it failed. i am unable to resolve it so help is required. My view input field is.
<div class="col-md-12">
<input type="text" id="refby" name="refby" style="" placeholder="ref by" /></div>
my js code is
$("#refby").typeahead({
source: function (query, process) {
return $.get("<?php echo base_url('get_doctor'); ?>", { query: query }, function (data) {
console.log(data);
data = $.parseJSON(data);
return process(data);
});
}
});
controller function is
public function get_doctor()
{
$check = $this->input->post('check');
$data = $this->customers->get_doctor($check);
echo json_encode( $data);
}
model function is
function get_doctor($check)
{
print_r($check);
$this->db->select('name');
$this->db->like('name', $check);
$this->db->from('doctors');
$query = $this->db->get();
return $query->result();
}
script link is
<script src="<?php echo base_url('assets/datatables/js/bootstrap3-typeahead.js'); ?>"></script>
console log is
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
<h4>A PHP Error was encountered</h4>
<p>Severity: 8192</p>
<p>Message: mysqli::real_escape_string(): Passing null to parameter #1 ($string) of type string is deprecated</p>
<p>Filename: mysqli/mysqli_driver.php</p>
<p>Line Number: 401</p>
<p>Backtrace:</p>
<p style="margin-left:10px">
File:home/vol5_2/infinityfree.com/if0_39199666/htdocs/application/models/Customers.php<br />
Line: 300<br /> Function: like</p>
<p style="margin-left:10px">
File: /home/vol5_2/infinityfree.com/if0_39199666/htdocs/application/controllers/Customer.php<br />
Line: 346<br />
Function: get_doctor</p>
<p style="margin-left:10px">
File: /home/vol5_2/infinityfree.com/if0_39199666/htdocs/index.php<br />
Line: 315<br />
Function: require_once</p>
</div>[{"name":"SELF"},{"name":"DR. ASIM IRSHAD"},{"name":"DR. ABDUL HAMEED KHAN"},{"name":"DR. MUHAMMAD SAFDAR CH"},{"name":"DR. SAFDAR HUSAIN BUKHARI"},{"name":"DR. ANSAR MEHBOOB"},{"name":"DR. SAJID MEHMOOD KHAN"},{"name":"DR. MAZHAR ABBAS KHAN"},{"name":"DR. ASMA MALIK"}]
VM135:2 Uncaught SyntaxError: Unexpected token '<', "
<div style"... is not valid JSON
at JSON.parse (<anonymous>)
at n.parseJSON (jquery-2.1.4.min.js:4:5497)
at Object.success (reception:626:27)
at j (jquery-2.1.4.min.js:2:26925)
at Object.fireWith [as resolveWith] (jquery-2.1.4.min.js:2:27738)
at x (jquery-2.1.4.min.js:4:11253)
at XMLHttpRequest.<anonymous> (jquery-2.1.4.min.js:4:14765)
while on localhost console log is
[{"name":"SELF"},{"name":"DR. ASIM IRSHAD"},{"name":"DR. ABDUL HAMEED KHAN"},{"name":"DR. MUHAMMAD SAFDAR CH"},{"name":"DR. SAFDAR HUSAIN BUKHARI"},{"name":"DR. ANSAR MEHBOOB"},{"name":"DR. SAJID MEHMOOD KHAN"},{"name":"DR. MAZHAR ABBAS KHAN"},{"name":"DR. ASMA MALIK"}]
so where lies the problem and what is the solution.
where lies the problem
...where the error message tells you it lies: " mysqli::real_escape_string(): Passing null to parameter #1 ($string) of type string is deprecated" . If you have error reporting enabled then any warning/error will cause PHP to output a HTML-formatted error message. Of course, this is not JSON. In a live environment you shouldn't really have reporting enabled in the output, it should be logged to a file instead - you can configure PHP to do this.$this->input->post('check')
will returnnull
if there is no element with a key ofcheck
in the $_POST payload. Did you print out$this->input->post()
to see what is actually hitting your controller? I don't seecheck
in your view. I do seerefBy
. How exactly are you expecting->like()
to inject your 2d array of submission data?