empty ajax,Empty request body on jQuery JSON ajax request

Server: Django 1.4 running on Heroku. All requests are HTTPS.

My ajax calls look like this:

var data = {

username: form.find('input[name="username"]').val(),

email: form.find('input[name="email"]').val()

};

$.ajax({

url: '/register',

type: 'POST',

data: JSON.stringify(data),

contentType: 'application/json',

dataType: 'text',

headers: {

'X-CSRFToken': $.cookie('csrftoken')

}

});

Occasionally, parsing the request body on the server fails because request.body is completely empty. It's fairly rare, but since I use this idiom on many pages, I see it a few times each week. Probably about 2-5% of these requests.

The CSRF token header is there along with the rest, so it appears that only the body itself is missing. In a recent request, I noticed a CONTENT_LENGTH 2 header as well, which would be too short to contain the real request data. I wonder where that got added.

I would love some help debugging this. I can't see any way for the JSON.stringify call to return the empty string. Is that reasonable? If so, then it has to be that the request body is either getting stripped off in-flight, or something in my Django application is doing it.

Any help debugging or ideas on how to reproduce this would be most welcome.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值