Answer the question
In order to leave comments, you need to log in
Django and jQuery (AJAX) - no answer?
Esteemed the tutorial on jQuery, and AJAX in particular. I wanted to tie the whole thing to Dzhanga. I started trying the tutorial here: webcloud.se/log/AJAX-in-Django-with-jQuery/
In Django, everything is simple, we have this method:
def ajax(request):<br/>
if request.is_ajax():<br/>
message = 'Hello world!'<br/>
else:<br/>
message = 'Hello'<br/>
return HttpResponse(message)<br/>
$(document).ready(function(e) {<br/>
$('#ajaxButton').click(function(){<br/>
$('#ajaxdiv').load("http://***.***.***.***:8000/test_ajax");<br/>
}); <br/>
});<br/>
It seems like it couldn't be easier, however... I open a page on a free hosting, I press a button, nothing happens. In the Janga server console, you can see that the get request has successfully arrived. I looked in Firebug - there is no response body (when if you just open the server page in the browser, then there is a response body in the request - it contains the line "Hello"). At the same time, another phenomenon for me is that the Janga server receives a Get request only if I click on the button in Firefox, nothing is sent in other browsers. Answer the question
In order to leave comments, you need to log in
It is impossible (without perversions) to send AJAX requests from one domain to another. More precisely, you can send, you can not read the answer. This is called the same origin policy (there are workarounds: JSONP and cross-origin requests). I strongly advise you to put aside learning jQuery and django and learn the basics of HTTP, HTML, and Javascript, as well as how browsers work. Using frameworks does not negate knowledge of the basics.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question