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. 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";
                            }
                        });
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);
                     } });

My views.py:

def test(request):
    print request.POST
    print request.GET
    return HttpResponse('test')
The problem is the request.POST is empty. If I set the 'type' to GET:
the request.GET contains 2 elements which I sent as parameters. I have
searched the web for ages and did not find a solution to this problem.
I can solve the problem using GET, however, the data I sent may be
large and requires some kinds of structure. Please if anybody has
experience on this. There is a user with similar problems:

http://groups.google.com/group/django-users/browse_thread/thread/d01903c1a85f79ed/8573e61b2f8e296d?lnk=gst&q=external+post+request#8573e61b2f8e296d

I have disabled all CSRF protections just to test this.
P/s: I have a log in page and some other pages using jQuery to
generate cross domain GET requests and they work fine. The problem
only arises when I use POST.

Thanks,
Viet Nguyen

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