gpt4 book ai didi

javascript - AngularJS $http.post 错误意外的 token F

转载 作者:可可西里 更新时间:2023-11-01 13:33:10 25 4
gpt4 key购买 nike

我正在尝试运行我的 $http.post 脚本,但出现错误,我尝试四处搜索但找不到问题的任何答案。这是我遇到的错误'当我运行我的网页时得到。

XHR finished loading: POST "http://mypage/services/json/DownTimeStartByDepartmentId.aspx?CategoryId=-1&Comment=&DepartmentId=6".


SyntaxError: Unexpected token F
at Object.parse (native)
at fromJson (http://10.19.13.67/apps/resources/scripts/angular.js:1037:14)
at $HttpProvider.defaults.defaults.transformResponse (http://10.19.13.67/apps/resources/scripts/angular.js:6948:18)
at http://10.19.13.67/apps/resources/scripts/angular.js:6923:12
at Array.forEach (native)
at forEach (http://10.19.13.67/apps/resources/scripts/angular.js:304:11)
at transformData (http://10.19.13.67/apps/resources/scripts/angular.js:6922:3)
at transformResponse (http://10.19.13.67/apps/resources/scripts/angular.js:7594:17)
at wrappedCallback (http://10.19.13.67/apps/resources/scripts/angular.js:10966:81)
at http://10.19.13.67/apps/resources/scripts/angular.js:11052:26

这是我要运行的脚本:

function Model($http) {
var self = this;
self.DowntimeCategories = [];
self.PreviousDowntimeEvents = [];

self.savedata = function () {
$http({
method: 'POST'
, url: 'http://mypage/services/json/DownTimeStartByDepartmentId.aspx'
, params: {
DepartmentId: 6
, CategoryId: -1
, Comment: ""
}
, headers: {'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8'}
}).success(function (data, status, headers, config) {
console.log(data);
}).error(function (data, status, headers, config) {

});
}
Hesto.Ajax.ngget($http, GET_CATEGORIES_NAMES, "", function (data) {
self.DowntimeCategories = data.data;
});
}

angular.module('myApp', [])

.controller('DowntimeController', function ($scope, $http) {
$scope.Model = new Model($http);
$scope.currentdowntime = function () {
console.log($scope.Model);
}
$scope.printmodel = function () {
console.log($scope.Model);
$scope.Model.savedata();
}
});

HTML:

<div id ="bodyui" ng-app="myApp">

<div ng-controller="DowntimeController">


<label><strong>SELECT A CATEGORY NAME :</strong></label><br />
<select ng-model="Model.CurrentDowntimeEvent.CategoryId" ng-options="downtimeCategory.CategoryId as downtimeCategory.CategoryName for downtimeCategory in Model.DowntimeCategories">
</select>
<input type="text" ng-model="Model.CurrentDowntimeEvent.Comment" />
<input type="button" value="currentdowntime" ng-click="currentdowntime()"/>
<input type="button" value="savedata" ng-click="printmodel()"/>

</div>
</div>

最佳答案

我遇到了同样的问题。服务器返回的 json 格式不正确。

关于javascript - AngularJS $http.post 错误意外的 token F,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24653740/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com