Angular $ http在200响应上调用错误

cla*_*ent 8 javascript angularjs

我在Angular服务中使用此代码: -

var formData = function (data) {
   var fd = new FormData();
   angular.forEach(data, function (value, key) {
      fd.append(key, value);
   });
   return fd;
}

var updateUserPic = function (profilePic, callback, userId) {
   var userId = userId || FRAME_API.proxyUserId; // jshint ignore:line
   if (!_.isFunction(callback)) {
      throw new Error('You must provide a callback function.');
   } 
   $http({
      method: 'POST',
      url: '/Learn/PostUserProfile.ashx?action=profilepic&userid=' + userId,
      data: {up_picfile: profilePic},
      transformRequest: formData,
      headers: { 'Content-Type': undefined}
   }).success(function (data, status, headers, config){
      callback([data, status, headers, config]);
      return;
   }).error(function (data, status){
      console.log([status,data]);
      callback(false);
      return;
   });
};
Run Code Online (Sandbox Code Playgroud)

使用Chrome开发者工具中的"网络"标签检查表明存在200 OK响应.数据也按预期进行.然而,问题是error回调是唯一一个被调用的,不管它的状态是200.而且datastatus参数也是如此undefined.

这种情况会是什么原因?

服务器的响应如下:

{status: 'success', path: 'assets/profile/profilepicture.png'}
Run Code Online (Sandbox Code Playgroud)

另请注意,我无法更改此响应.它来自在服务器上运行的供应商脚本,我无法访问.

cla*_*ent 3

我使用自定义响应转换器将其转换为有效的 JSON:

var responseTransformer = function (data) {

   return data.replace('status', '"status"')
              .replace('\'success\'', '"success"')
              .replace('path', '"path"')
              .replace('\'assets/profile/profilepicture.png\'',
                       '"assets/profile/profilepicture.png"');

};
Run Code Online (Sandbox Code Playgroud)

这使得它工作得很好。