0

I am trying to send GET request to Django. In the script:

$http({ 
    method: 'GET', 
    url: 'response/',
    data: 'test=data',
}).success(function(data, status, headers, config){
    console.log(data);
});

In the view response() function, if I try

def response(request):
    data = json.loads(request.body)
    return HttpResponse(data)

I will get 500 (INTERNAL SERVER ERROR). If I try

def response(request):
    data = request.body
    return HttpResponse(data)

the returned data is empty. I wonder what is happening?

2 Answers 2

2

do it like this:

$http({ 
  method: 'GET', 
  url: 'response/',
  data: $.param({
    'test': 'data
  })
}).success(function(data, status, headers, config){
  console.log(data);
});

and use request.GET -

def response(request):
    data = request.GET.get('test')
    return HttpResponse(data)
Sign up to request clarification or add additional context in comments.

Comments

0

We can use the code like this.

$http({ 
   method: 'GET', url: '../../load/', 
   data: {'test': 'Nath'}, 
   header: {'Content-Type': 'application/x-www-form-urlencoded'}
}).then(function (data) {
   var ck = data.data;
 }, function(response) { console.log("failed to load data."); });

views will be

def response(request):
    data = request.GET.get('test')
    return HttpResponse(data)

it worked..

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.