で十分ですdajaxice
。今、私はjQueryを使用して脳を破壊しようとしています。
以前、私はやっていて$.get
、すべてが大丈夫でした。さて、$.ajax
(get)で試してみると、これが私が持っているものです:
urls.py
from django.conf.urls import patterns, include, url
from BitProject.views import index_page,xhr_test
urlpatterns = patterns('',
(r'^$', index_page),
url(r'^ajaxrequest/$', xhr_test, name='ajaxurl'),
)
views.py
from django.http import HttpResponse
from django.shortcuts import render_to_response
from django.utils import simplejson
def index_page(request):
return render_to_response ('template_1.html')
def xhr_test(request):
if request.is_ajax():
message = "Hello AJAX"
else:
message = "Hello"
return HttpResponse(simplejson.dumps(message), mimetype="applicaton/json")
template_1.html
<html>
<head>
{% load staticfiles %}
<link rel="stylesheet" href="{% static "css/style_2.css" %}" type="text/css">
<script src="{% static "js/jquery_v183.js" %}"></script>
<script>
$(document).ready(function(){
$('#picture_1').click(function(){
$.ajax({
url:"/BitProject/ajaxrequest/",
type: 'GET',
success: function(data){
$('#someEl_2').html(data)
},
dataType: JSON
});
});
});
</script>
</head>
<body>
<img src="{% static "images/sunny.png" %}" id="picture_1" magrin='10px'/>
<div id="someEl_2">First Text</div>
</div>
<body>
</html>
クロームを使用しています。コンソールに、応答があることがわかります-応答タブで- Hello AJAX
。しかし、ページでは何も起こりません。私の問題はどこにありますか?