【问题标题】:AngularJS $http.post error Unexpected token FAngularJS $http.post 错误意外的令牌 F
【发布时间】:2014-08-20 21:33:29
【问题描述】:

我正在尝试运行我的 $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?你能发布回复吗?
  • @rob 我编辑了我发布的脚本,你可以看看它
  • 我仍然没有看到您的服务器返回的响应
  • 它告诉您您的 JSON 响应不正确。您需要发布它(或它的样本)
  • 我的 JSON 响应不正确是什么意思?

标签: javascript html angularjs


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-13
    • 2011-12-20
    • 2015-11-19
    • 2018-08-27
    相关资源
    最近更新 更多