PHP接口返回空字符串,在PHP中返回空字符串

當我在文本框中使用某些字符(如/)時,我在response中返回empty string。我可以很容易地檢查我的html中的empty string,但我的問題是如何避免在我的php代碼中發送空字符串?在PHP中返回空字符串

$("#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');

}

?>

foreach($posts->result() as $m) :

if($m->post_status != 'active' OR empty($m->post_title)) continue;

?>

<?php echo $m->post_url; ?>

}

+0

用/作爲轉義字符,使用控制檯日誌和的var_dump檢查您發送的信息和recieving。 –

+0

@Aschab控制檯打印輸出「(一個空字符串)」 –

+0

console.log($(this).val())給你空字符串? –

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值