我有這樣的代碼json_encode問題
if($_POST){
// response hash
$response = array('type'=>'', 'message'=>'');
try{
// do some sort of data validations, very simple example below
$required_fields = array('name');
foreach($required_fields as $field){
if(empty($_POST[$field])){
throw new Exception('field is empty');
}
}
// ok, field validations are ok
// now add to data to DB, Send Email, ect.
// let's assume everything is ok, setup successful response
$response['type'] = 'success';
$response['message'] = "Done";
}catch(Exception $e){
$response['type'] = 'error';
$response['message'] = $e->getMessage();
}
// now we are ready to turn this hash into JSON
print json_encode($response);
exit;
}
,我想重定向到 '成功' 後頁面(ok.html)。我怎樣才能使它
問候
爲什麼要在返回JSON時重定向到HTML頁面?我不明白。 – 2011-02-23 20:19:34
我的猜測是,在成功消息返回 – 2011-02-23 20:21:24
@Pekka之後,我想用'window.location'從客戶端重定向,因爲Pin Cody並不瞭解HTTP工作原理。 – zzzzBov 2011-02-23 20:29:26