jquery - Django and AJAX : completely lost -
jquery - Django and AJAX : completely lost -
my question in more appropriate way hope:
essai.html:
<html> <head> <title> ajax </title>, <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script type="text/javascript" src="/static/js/ajax.js"></script> </head> <body> <div class="wrapper"> <h3>ajax callback introduction</h3> <div class='entry_wrapper'> <h4>data send server:</h4> <input type="text" size="50" id="input_text"/> <input type="button" value="ajax phone call back" id='call_back_btn'/> </div> <div class='response_wrapper'> <textarea id='responsetext'></textarea> </div>
ajax.js:
$(document).ready( function() { $('#call_back_btn').click(function() { $.post("{% url 'friend' %}", { person_name: $("#input_text").val() }, function(data) { $('#responsetext').val(data) } ); }); } );
views.py:
from django.http import httpresponse def friend(request): if request.method == 'post': nom=request.post.get("person_name") homecoming httpresponse (nom)
urls.py:
from django.conf.urls import patterns, url planner import views urlpatterns = patterns('', url(r'^$', views.index, name='index'), url(r'^essai/', views.essai, name='essai'), url(r'^friend/', views.friend, name='friend'), )
the problem: when click on ajax phone call button: text send if not mistaken because next result in firebug:
http://127.0.0.1:8000/planner/essai/%7b%%20url%20%27friend%27%20%%7d 200 ok 13ms
and in post area :
person_name try
however, text not returned text area (id='responsetext'). instead total content of essai.html field:
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <!--css--> <link href="/static/css/bootstrap.css" rel="stylesheet" type="text/css" /> ...
jquery python ajax django
Comments
Post a Comment