**var ajaxUrl='admin/includes/validation.php?ref=enquiry&name='+$("#name").val() + '&email1='+$("#email1").val() + '&phone='+$("#phone").val()/*+ '&check='+a*/;
$.ajax({
type: "POST",
url: ajaxUrl,
data: "",
dataType: 'json',
success: function(msg){
//alert(msg);
if(msg!="")
{
$(".error").html("");
$(".err").attr("style","");
$.each(msg,function(key, value) {
if(value!="") {
//alert(value);
$("#"+key).attr("style","border:2px solid #000000;");
$("#Enq_"+key).html(value);
}
});
}
else
{
$("#contact").submit();
}
}
});**
Php file:
*if(!empty($check))
{
$countema = "select id, email from contactus where email='".$email."' ";
$exe_query=$Obj->_query($countema);
$fetch_Mail= $Obj->_fetch_array($exe_query);
$mail=($fetch_Mail['email']);
if(!empty($email) && ($email== $mail)){
echo 'This Email id already subscribed ';
}
/*$query=" insert into `news` set `email`='".escapestr($email)."',`status`='1', createddate='now' ";
$exe_query=$Obj->_query($query);
}
else
{
$query=" insert into `news` set `email`='".escapestr($email)."',`status`='1', createddate='now' ";
$exe_query=$Obj->_query($query);
}*/
答案 0 :(得分:0)
在这里使用json_encode
$resp = array();
if(!empty($email) && ($email== $mail)){
$resp['data'] = 'This Email id already subscribed ';
}
echo json_encode($resp);
答案 1 :(得分:0)
您的JavaScript
代码需要JSON
,您返回的内容为text/plain
。字符串This Email id already subscribed
不是有效的JSON
对象。有效JSON
将是
{ "error" : true }
或类似的东西。在这种情况下,了解如何告诉前端是否发生错误。
您可以这样使用它:
success: function(msg){
if (msg.error) { alert('An error has occurred! Everybody, get down!'); }