我只是想知道是否有一种方法可以在使用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