Answer the question
In order to leave comments, you need to log in
Why can't it find the file and give a 404?
I'm trying to send a post request, but for some reason I'm getting a 404.
What's wrong?
js code:
var doc = document;
function jax(url,post,post_data)
{
var return_data = 0;
var hr = new XMLHttpRequest();
var uri = url;
hr.open("POST", uri, true);
hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
var post = post;
var vars = post + post_data;
//console.log(vars);
hr.onreadystatechange = function()
{
if(hr.readyState == 4 && hr.status == 200)
{
var return_data = hr.responseText;
console.log(return_data)
}
}
hr.send(vars);
}
var adres = 'hello';
doc.getElementById('go').onclick = function()
{
jax('http://127.0.0.1:8000/search/',"go=",adres);
}
# -*- coding: utf-8 -*-
from django.shortcuts import render_to_response
from django.http import HttpResponse
from django.shortcuts import render_to_response
def hello(request):
return render_to_response('test.html')
def search(request):
if 'go' in request.POST:
message = 'You searched for: %r' % request.POST['go']
else:
message = 'You submitted an empty form.'
return HttpResponse(message)
from django.conf.urls import url
from django.contrib import admin
from django_test.views import hello
urlpatterns = [
url(r'^hello/$', hello),
]
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question