How request a JSON with ajax on AngularJS? I have written my site on django. On get request to 0.0.0.0:8000/json/ ,it sends back a json.object
At django, part views.py:
def send_json(request, param):
result_dict = dict()
result_dict['hello'] = 'world'
return HttpResponse(json.dumps(result_dict, ensure_ascii=False), content_type="application/json; encoding=utf-8")
When I visit 0.0.0.0:8000/json/ in browser, I see json.
On Angular, I have read this article - fdietz.github.io/recipes-with-angular-js//consuming-external-services/requesting-json-data-with-ajax.html and implemented my code
(function(){
angular.module('myapp',[])
//define controller and inject $http service as dependency.
.controller('ajax',['$http','$scope',function($http,$scope){
$http.get('0.0.0.0:8000/json/').success(function(data, status, headers, config) {
$scope.posts = data;
}).
error(function(data, status, headers, config) {
});
}])
})();
GET request in Django is working but nothing is being displayed. When I change link at angular to fetch a local json it's working perfectly.
What is the mistake I am making?