【发布时间】:2014-09-14 07:04:26
【问题描述】:
我在 angularJs 中为 $http 编写代码时收到 500 个服务器错误。我正在使用 Ubuntu 操作系统
代码如下
$http({
method: 'POST',
url: 'http://localhost.com/domain/index.php?r=site/CheckDomain',
headers: {'Authorization': 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=='},
data: {urlName: $scope.urlName, domainExt: $scope.domainExt},
}).success(function(data, status, headers, config) {
toaster.pop('success', "Successer", 'Total 7 Result Found', 25000, 'trustedHtml', '');
//$scope.domainExt = data;
$scope.results = data.records;
$scope.showresult = true;
//Code use to assign default values in price dropdown
angular.forEach($scope.results, function(value, key) {
$scope.model[key] = value.selectedOption.dp_id;
});
}).error(function(data, status, headers, config) {
});
回复如下
访问控制允许原始...http://localhost.com/domain/
连接关闭
内容类型 text/html
日期 2014 年 9 月 14 日星期日 06:52:46 GMT
服务器 Apache/2.4.7 (Unix) OpenSSL/1.0.1f PHP/5.5.9 mod_perl/2.0.8-dev Perl/v5.16.3
X-Powered-By PHP/5.5.9
接受 application/json、text/plain、/
接受编码 gzip,放气
Accept-Language en-US,en;q=0.5
授权基础 QWxhZGRpbjpvcGVuIHNlc2FtZQ==
内容长度 38
内容类型 application/json;charset=utf-8
Cookie KCFINDER_showname=on; KCFINDER_showsize=off; KCFINDER_showtime=off;
KCFINDER_order=name; KCFINDER_orderDesc=off; KCFINDER_view=拇指;
KCFINDER_displaySettings=off
主机 localhost.com
【问题讨论】:
-
服务器返回给客户端的数据必须是json格式。将数据转换成它。不会再出现这个错误
-
@mironyks 数据仅以 json 格式提供。我正在使用“json_encode($result);”功能。代码在 Windows 机器上运行良好,仅在 Ubuntu 操作系统中面临问题