【发布时间】:2014-08-31 16:23:22
【问题描述】:
我有一个可以发表评论的脚本。一切正常,但我需要它,所以如果发现 php 有任何错误,它会提醒用户错误,否则它会显示评论
这里是ajax部分
$.ajax({
type: 'POST',
url: 'comment/post.php',
data: ajaxData,
processData: false,
contentType: false,
dataType: "json",
success:function(result){
if(result.error == true){
alert(result.error);
} else {
$('#comments').prepend(result.comment);
}
}
});
和php(注意这只是一部分,但你应该明白)。因此,如果有错误,它应该发出警报,否则评论应该通过。但它不起作用
if(isset($_FILES['file'])){
$image_key = sha1(uniqid(mt_rand(), true));
$new_image_name = $image_key.'.jpg';
move_uploaded_file($_FILES['file']['tmp_name'], '../uploads/'.$new_image_name);
$file = '<img src="uploads/'.$new_image_name.'" />';
$Comment->addImage($new_image_name, $random);
echo json_encode(array('error' => true, 'Your file was too big'));
}
echo json_encode(array('comment' => 'Here is your comment blah blah'));
header('Content-type: application/json');
【问题讨论】:
-
使用回声一次...将两个数组绑定在一起...就像一个 json 对象 thrn 编码并返回