When I use some characters like / in the textbox I get returned an empty string in response. I can easily make a check for empty string in my html but my question is how can I avoid having that empty string from being sent over in my php code?
$("#search").keyup(function(){
var newVal = $(this).val();
if(!newVal==""){
$.ajax({
type : 'get',
dataType: 'html',
url : '/searchpost/' + newVal ,
success : function(response) {
console.log(response);
}
});
}
});
public function searchpost() {
$q = $this->uri->segment(3);
if(!$q) die();
$string = trim(strip_tags($q));
$db_string = urldecode($string);
$this->db->select("postID, post_title, post_url, post_status");
$this->db->like("post_title", $db_string);
$this->db->or_like("post_url", $db_string);
$posts = $this->db->get('posts', 10);
if(!count($posts->result())) {
die('Nothing to display');
}
?>
<ul>
<?php
foreach($posts->result() as $m) :
if($m->post_status != 'active' OR empty($m->post_title)) continue;
?>
<li>
<a href="<?php echo '/posts/'.$m->postID.'/'.url_title($m->post_title); ?>" class="url-post-title" style="font-size:14px;"><?php echo $m->post_url; ?></a>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php
}