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的
,则在之后发出警报