Ajax response returns empty value. Network response shows the value
Ajax response returns empty value. Network response shows the value
I'm having a really weird problem where a certain value from an ajax json response is an empty string. All other values are coming through fine.
The weird part is that when I look at the response in the network panel it shows the correct value. By the time I console log it, it's empty.
I'm really not sure where to begin at debugging this.
It's a pretty simple ajax call. I'm using a factory and logging the response.
getAllActivity: function(){ return $http({ method: 'GET', url: '/getActivity' }); } feedFactory.getAllActivity().success(function(response){ console.log(response); });
The response from the log shows:
{ "__type": "ActivityService", "activityTime": "/Date(1414189623937-0600)/", "activityTimeString": "2014-10-24T16:27:03.9370000-06:00", "activityType": "Appreciation", "activityUrl": "~/Blog/August-2014/Staggering-the-Line", "activityUser": { "userId": 12345, "userNickName": "Mike_Jones" }, "itemDescription": "" }
The response from the network panel shows:
{ "__type": "ActivityService", "activityTime": "/Date(1414189623937-0600)/", "activityTimeString": "2014-10-24T16:27:03.9370000-06:00", "activityType": "Appreciation", "activityUrl": "~/Blog/August-2014/Staggering-the-Line", "activityUser": { "userId": 12345, "userNickName": "Mike_Jones" }, "itemDescription": "test" }
Also, it's working fine on other activityTypes. The object is exactly the same, the only difference being the value isn't returned as an empty string.
I appreciate any help.
Thanks to Michal in the comments I was able to see the value by using
console.log(angular.copy(response));
However when I try to use that var foo = angular.copy(response); function doWhatEva(foo);
Inside doWhatEva it is empty again.
Answer by MrMins for Ajax response returns empty value. Network response shows the value
Try adding the dataType:json
to your request
getAllActivity: function(){ return $http({ type: "GET", dataType: "json", url: '/getActivity' }); }
Answer by user2755150 for Ajax response returns empty value. Network response shows the value
It should be useful to see what is doing and returning "getActivity" url, maybe the value for itemDescription is coming up with a weird character or something.
Answer by rahpuser for Ajax response returns empty value. Network response shows the value
I think you have a deserialization problem because that is not a valid json:
"activityUser": { "userId": 12345, "userNickName": "Mike_Jones", } "userNickName": "Mike_Jones",
There is a comma more, did you already fix that ?
Answer by Daredzik for Ajax response returns empty value. Network response shows the value
try this, should works:
getAllActivity: function(){ var result = $http({ method: 'GET', url: '/getActivity' }); return (result.then(function(r){return r.data})); }
Answer by Michal Charemza for Ajax response returns empty value. Network response shows the value
As discussed in the comments, the output from
console.log(response)
was missing the value, but the output from
console.log(angular.copy(response))
had the missing value present. Because console.log
can show objects not as they are at the time of calling console.log
, but at the end of the JS event loop, this suggests that the value was returned from the server properly, and Angular was decoding it fine from the JSON, but that the value was being changed later, in some code not contained in the original question.
Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72
0 comments:
Post a Comment