S
S
S0ulReaver2012-04-06 22:02:53
JavaScript
S0ulReaver, 2012-04-06 22:02:53

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/>

Accordingly, when trying to access the URL in browsers, everything is without problems. Janga itself is spinning on my machine - the dev server, respectively.

The page with jQuery is located on one of the free hosting, such content:

$(document).ready(function(e) {<br/>
$('#ajaxButton').click(function(){<br/>
 $('#ajaxdiv').load(&quot;http://***.***.***.***:8000/test_ajax&quot;);<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.

With what such problems can be connected?

Django version 1.2.7, jQuery 1.7.2

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
egorinsk, 2012-04-06
@S0ulReaver

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 question

Ask a Question

731 491 924 answers to any question