javascript - Angular $http calls error on 200 response -
i have code used within angular service:-
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 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; }); };
inspecting using network tab in chrome's developer tools shows there 200 ok
response. data goes through expected. however, problem error
callback 1 ever called regardless of fact has status of 200. data
, status
parameters come in undefined
.
any reason case?
the response server this:
{status: 'success', path: 'assets/profile/profilepicture.png'}
also, note response cannot changed me. coming vendor's script running on server cannot access.
i used custom response transformer turn valid 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"'); };
this made work fine.
Comments
Post a Comment