Help with ajax in Django 1.6.5 - ERROR 500

-1

I would like to know why I'm launching a server error (500). I need to make or import some other type of library or module to run my request ajax ?

$("#email").change(function(){
                $.ajax({
                    data : { "email": $(this).val() },
                    url : "/validar-email/",
                    type : "GET",
                    dataType : 'json',
                    contentType: 'application/json; charset=UTF-8',
                    success : function(data){
                        console.log(data);
                    }
                });
            });

Function in the view

def ValidarEmail(request):
    if request.is_ajax():
        data = serializers.serialize('json', {'respuesta':'ok'})
        return HttpResponse(data, content_type='application/json')
    
asked by Ariel Gavegno 13.07.2016 в 00:24
source

1 answer

-1

I do not know much about Django but the error 500 means that you have an error in the server, which is being caused by the validateEmail function, reading a bit the documentation the error is due to the fact that as a second meter for the seralize function you are passing a string and not a QuerySet, to solve this you could use the JsonResponse function (available from django 1.7) as follows:

from django.http import JsonResponse
def ValidarEmail(request):
if request.is_ajax():
    data = {'respuesta':'ok'}
    return HttpResponse(json.dumps(data), content_type='application/json') //esto deberia funcionarte 
    return JsonResponse({'respuesta':'ok'})//djan1.7+
    
answered by 13.07.2016 в 03:57