[英]How to avoid alert box in php
我只想在我回聲時才得到警報。當我不給出echo語句時會顯示空警報框。我只想在'if'條件之后才顯示警報。
$.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";
}
嘗試像
$.ajax({
type:'post',
url:'email.php',
data:{email: email},
success:function(msg){
if($.trim(msg) != '') {
alert(msg);
}
}
});
您也可以使用Length
msg = $.trim(msg);
if(msg.length > 0) {
alert(msg);
}
檢查味精的長度
success:function(msg){
if (msg.length> 0) {
alert(msg);
}
}
說明:
有兩個條件:
1)您正在回聲。
2)您沒有回聲。
在第一種情況下,您將獲得大於0
的msg
長度。
在第二種情況下,您將獲得的長度為0
,因此,不會出現alter。
用味精長度做它的簡單方法。
這是因為空格進入了msg變量:
請嘗試以下操作:var string = msg.replace(/ + / g,“”);
if(string!=“”){alert(msg);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.