Unable to send string in HTTP POST
21:40 12 Dec 2014

So, I'm new to web development and I need to send a POST request to a server. Here's the code:

HTML:



JavaScript:

function httpPOST(data)
{
    var client = new XMLHttpRequest();
    var url = "http://193.136.19.86:8080/restaurants/login/";

    client.open("POST", url, true);
    client.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    client.send(data);
}

The code works fine if in the email.value there is a number, or even a bool. For example, if I write "2" in the "email" input, the server receives it pretty well. However, when I write a real email (or other string), it gives me a 500 (INTERNAL SERVER ERROR).

Any idea on what I am doing wrong?

Here is the view of the server, developed using Django:

@csrf_exempt
def logtrans(request):
    #print(request)                                                                                                                                     
    context= RequestContext(request,{})
    d=json.loads(request.body)
    if request.method == 'POST':
        print(d)
    return HttpResponse("Done")

Thanks in advance!

javascript html django post