On 2010-10-22, at 11:53 , Viet Nguyen wrote:
> Hi there, I am quite new to Django and encounters a problem which
> takes me a lot of time to figure out. As I known, Django provides some
> functionality to prevent cross domain AJAX requests.
Last time I checked, Django didn't integrate any ajaxy facilities and let 
developers do whatever they wanted on that front. In fact, Django would be 
quite unable to manage cross-domain xhr requests considering that's a feature 
of JS clients aka your web browser.

> However, using
> jQuery you can specify a callback (JSONP) and could talk and get data
> back from the server. For example:
> 
> $.getJSON('http://127.0.0.1:8000/biotool/prepDownload/login/?user=' +
> uName + '&password=' + pWord + '&callback=?',
>                       function (data) {
>                           if (data != null) {
>                               Load.displayPackages(data);
>                               window.location = "#_sepa";
>                           }
>                           else {//request failed
>                               var element = 
> document.getElementById("loginError");
>                               element.innerHTML = "Could not authenticate 
> with server";
>                           }
>                       });
Please note that you're not doing what you're talking about at all here. jQuery 
provides built-in facilities for jsonp namely the 'jsonp' dataType which can be 
provided as an option to most jQuery ajax calls. But the code above doesn't use 
jsonp, as far as I can tell it uses regular json.

> However, for some cases, when you need to send a large amount of data
> to the server (in JSON format), you may have to use $.post(). This is
> a sample section of code:
> 
>              $.ajax( {
>                        'url': 'http://127.0.0.1:8000/biotool/
> prepDownload/test/',
>                        'type': 'POST',
>                         'data': {'rowID': '2', 'taxon': 'aaa'},
>                        'success': function (s) {
>                                 alert (s);
>                     } });
Again, you're not using jQuery's jsonp facilities here. But in any case, jsonp 
the way it is generally implemented (via <script> tags) usually can't be used 
via POST. In that case, you generally want to build yourself some kind of proxy 
server which will be able to forward your queries to the remote service.

> 
> My views.py:
> 
> def test(request):
>    print request.POST
>    print request.GET
>    return HttpResponse('test')
In any case, jsonp requires cooperation between the server and the client. And 
again, django has none built in that I know of, so you're not doing jsonp 
anywhere.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to