我只是想知道是否有一種方法可以在使用json_decode回顯響應時繞過所有PHP消息。用AngularJS忽略PHP消息
我目前的問題是,如果我的PHP代碼有任何回聲或其他任何包含在輸出中的數組除外,我的Javascript根本無法工作。
PHP:
<?php
error_reporting(1);
$errors = array();
$data = [];
// data from angular to be handled and
// then if all goes well set submission to true to display with ng-show
$data["submission"] = true;
header('Content-Type:application/json;');
echo json_encode($data);
?>
JS:
$scope.testProcessForm = function() {
$http({
method : 'POST',
url : 'reg.php',
data : $scope.formData,
headers : {'Content-Type': 'application/x-www-form-urlencoded'}
})
.then(function(response) {
console.log(response);
$scope.submission = response.data.submission;
}, function(error) {
console.log('error', error);
我認爲通過使用response.data.submission我可以只訪問裏面有,但如上所提到的數據如果包含任何不在數組中的PHP輸出,代碼會中斷。
是否有可能只是訪問/響應$ data數組,以便它不會中斷?
你應該使用'error_log',而不是'echo'打印出調試信息/錯誤。使用'error_log'會把消息放到'php_error_logs'文件中。 –
如何不在PHP中輸出任何多餘的消息,並確保您輸出實際有效的JSON ...! – deceze