1

I've written a post request to execute method in Django, but I found when executing takes a little longer, nothing returned.

Here is a simple example, I've tested this.

Ajax code:

$.post('/test-time/', function(data) {
    alert(data);
})

In my Django views:

def testTime(request):
    for i in range(100):
        print i
        time.sleep(1)
    return HttpResponse('success!')

When time is 100s, It works, browser alert 'success!'.

But when I make the time a little longer, like:

def testTime(request):
    for i in range(400):
        print i
        time.sleep(1)
    return HttpResponse('success!')

Ajax won't get any return data, browser didn't alert.

Http server is Nginx, using uwsgi to run Django.

Hope you can help me, thank you :)

dexter182
  • 13
  • 3

2 Answers2

0

You are likely getting a timeout error; see this older SO post here: Set timeout for ajax (jQuery) and the link to .ajax() documentation therein.

Community
  • 1
  • 1
souldeux
  • 3,615
  • 3
  • 23
  • 35
0

Sorry, I've been out of Internet for several days.

The problem solved.

It is due to timeout, but not ajax timeout.

It's about nginx and uwsgi, simply added these configurations to the nginx.conf, the function worked.

uwsgi_connect_timeout 15;
uwsgi_send_timeout 8;
uwsgi_read_timeout 8;
dexter182
  • 13
  • 3