Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何避免php中的警报框_Javascript_Php_Jquery_Ajax - Fatal编程技术网

Javascript 如何避免php中的警报框

Javascript 如何避免php中的警报框,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,我只想在回显时获得警报。当我没有给出回显语句时,将显示空警报框。我只想在“如果”条件后显示警报 $.ajax({ type:'post', url:'email.php', data:{email: email}, success:function(msg){ alert(msg); } }); email.php $s=$_POST['email']; include "config.php"; $echeck="select email from register

我只想在回显时获得警报。当我没有给出回显语句时,将显示空警报框。我只想在“如果”条件后显示警报

 $.ajax({
 type:'post',
url:'email.php',
data:{email: email},
success:function(msg){
alert(msg);         
}
});

email.php

$s=$_POST['email'];
include "config.php";
$echeck="select email from register where email='".$_POST['email']."'";
$echk=mysql_query($echeck);
$ecount=mysql_num_rows($echk);
if($ecount>=1 && $s!='0')
{
  echo "Email already exists";
}
检查味精的长度

success:function(msg){
 if (msg.length> 0) {
  alert(msg);
 }
}

说明:

有两个条件:

1) 你在说些什么

2) 你不是在说什么

在第一种情况下,您将得到
msg
的长度大于
0

在第二种情况下,您将得到长度为
0
,因此,alter将不会出现。

请尝试类似操作

$.ajax({
  type:'post',
  url:'email.php',
  data:{email: email},
  success:function(msg){
      if($.trim(msg) != '') {
          alert(msg);        
      } 
  }
});
您可以使用
长度
也可以像

msg = $.trim(msg);
if(msg.length > 0) {
    alert(msg);
}

简单的方法来做它的味精长度


如果(msg.length>0)其原因是msg变量中有空格:

请尝试以下操作: var string=msg.replace(/+/g,“”)

如果(字符串!=“”){ 警报(msg)


}

检查javascript部分中的消息长度。如果处理了php的
,则在
之后发出
警报