AngularJS $ http.post错误意外标记˚F [英] AngularJS $http.post error Unexpected token F
本文介绍了AngularJS $ http.post错误意外标记˚F的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图运行我的 $ http.post
剧本,我得到一个错误,我试图寻找周围也没有找到我的问题的任何答案。这是当我运行我的网页,我得到的错误。
XHR加载完成:POST \"http://mypage/services/json/DownTimeStartByDepartmentId.aspx?CategoryId=-1&Comment=&DepartmentId=6\".
语法错误:意外的令牌˚F
在Object.parse(原生)
在fromJson(http://10.19.13.67/apps/resources/scripts/angular.js:1037:14)
在$ HttpProvider.defaults.defaults.transformResponse(http://10.19.13.67/apps/resources/scripts/angular.js:6948:18)
在http://10.19.13.67/apps/resources/scripts/angular.js:6923:12
在Array.forEach(原生)
在的forEach(http://10.19.13.67/apps/resources/scripts/angular.js:304:11)
在transformData(http://10.19.13.67/apps/resources/scripts/angular.js:6922:3)
在transformResponse(http://10.19.13.67/apps/resources/scripts/angular.js:7594:17)
在wrappedCallback(http://10.19.13.67/apps/resources/scripts/angular.js:10966:81)
在http://10.19.13.67/apps/resources/scripts/angular.js:11052:26
下面是我的脚本,我试图运行:
函数模型($ HTTP){
VAR自我=这一点;
self.DowntimeCategories = [];
。自previousDowntimeEvents = [];self.savedata =功能(){
$ HTTP({
方法:POST
,网址:'HTTP://mypage/services/json/DownTimeStartByDepartmentId.aspx
,则params:{
的DepartmentID:6
,类别ID:-1
,评论:
}
,标题:{内容类型:应用程序/ x-WWW的形式urlen codeD;字符集= UTF-8'}
})。成功(功能(数据,状态,头,配置){
的console.log(数据);
})错误(功能(数据,状态,头,配置){ });
}
Hesto.Ajax.ngget($ HTTP,GET_CATEGORIES_NAMES,功能(数据){
self.DowntimeCategories =数据。数据;
});
}angular.module('对myApp',[]).controller('DowntimeController',函数($范围,$ HTTP){
$ scope.Model =新模式($ HTTP);
$ scope.currentdowntime =功能(){
的console.log($ scope.Model);
}
$ scope.printmodel =功能(){
的console.log($ scope.Model);
$ scope.Model.savedata();
}
});
HTML:
< DIV ID =bodyuiNG-应用=对myApp> < DIV NG控制器=DowntimeController>
<标签><强>选择一个类别名称:LT; / STRONG>< /标签>< BR />
<选择NG模型=Model.CurrentDowntimeEvent.CategoryIdNG选项=downtimeCategory.CategoryId在Model.DowntimeCategories downtimeCategory.CategoryName为downtimeCategory>
< /选择>
<输入类型=文本NG模型=Model.CurrentDowntimeEvent.Comment/>
<输入类型=按钮值=currentdowntimeNG点击=currentdowntime()/>
<输入类型=按钮值=SAVEDATANG点击=printmodel()/> < / DIV>
< / DIV>
解决方案
我遇到了同样的问题。服务器返回的JSON格式不正确。
I'm trying to run my $http.post
script and I am getting an error,I tried searching around but couldn't find any answers to my problem.Here is the error that I'm getting when I run my web page.
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
Here is my script that I'm trying to run:
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>
解决方案
I ran into the same problem. The json returned by the server is not correctly formed.
这篇关于AngularJS $ http.post错误意外标记˚F的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文