又是我。
我有一些由 PHP 创建的错误,如下所示:
if (strlen($event_name) < 1){ echo $result['error'] = "<li>You must enter an event name</li>";}
if (strlen($venue_name) < 1){ echo $result['error'] = "<li>You must enter a venue name</li>";}
if (strlen($event_date) < 1){ echo $result['error'] = "<li>You must enter an event date - if not please write TBC</li>";}
if (strlen($address_l1) < 1){ echo $result['error'] = "<li>You must enter an address</li>";}
if (strlen($postcode) < 1){ echo $result['error'] = "<li>You must enter a postcode</li>";}
if (strlen($country) < 1){ echo $result['error'] = "<li>You must enter a country</li>";}
然后最后我得到了:
echo json_encode($result);
要将这些错误打印到我的 OL,我得到了这个:
$('#errorbox').html(result.error);
然而,没有任何结果......因为它没有出现。
编辑:这是完成 AJAX 后调用的函数:
}, function(result) {
if (result.success == true) {
$('#errorbox').html(result);
} else if (result.success == false) {
$('#errorbox').html("Not working dude!");
}
}, 'json');
return false;
}