我正在尝试验证 data.announce 但我收到此错误“Uncaught TypeError: Cannot read property 'announce' of null”
所以这是我的代码
.php 文件:
$return = array("msg" => "You'll recive an email with instructions!");
return json_encode($return);
jQuery:
$("form[id='common-handler/register'] #submit").click(function(e) {
e.preventDefault();
if(locked == 1)
return false;
locked = 1;
var _form = $(this).closest('form').attr('id');
$.post("/"+_form, $(this).closest('form').serialize(), function(data) {
if(!isEmpty(data.announce))
$("#search_bar").html(data.msg).fadeIn("slow");
else
$("form[id='" + _form + "'] p.msg").text(data.msg);
}, "json");
});
function isEmpty(str) {
return (!str || 0 === str.length);
}