**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);
}*/
问问题
97 次
2 回答
0
json_encode
在这里使用
$resp = array();
if(!empty($email) && ($email== $mail)){
$resp['data'] = 'This Email id already subscribed ';
}
echo json_encode($resp);
于 2013-04-26T07:08:37.523 回答
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!'); }
于 2013-04-26T07:09:03.283 回答