我将textarea内容thourgh ajax发布到django。 我的问题开始了。当我放置<1000行文本区域时,没有任何事情发生,并且工作正常。但是,如果放置1000行或大于10000行,我将收到错误的“错误请求”。所以我的问题是:是对json post ajax的任何限制,还是有人对此有解决方案?感谢您的帮助
这是我的ajax请求:
$.ajax({
type: "POST",
// url: '/page-tools/inboxpage/setting_send_inbox_ajax/{{page.pk}}/',
url: "{% url 'page-tools:page-settings-send-inbox-ajax' page.pk %}",
data: $(this).serialize(),
beforeSend: function(xhr, settings) {
function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) {
// Only send the token to relative URLs i.e. locally.
xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
}
},
success: function(response) {
if (response.error_connection) {
alert(response.error_connection);
} else if (response.error_token) {
alert(response.error_token);
} else {
send_inbox(response.settings);
}
},
error: function (jqxhr, status, exception) {
console.log('Exception: ', exception);
}
});
});
这是我在Django中的观点:
def settings_send_inbox_ajax(request, pk):
page = get_object_or_404(PageOwnerByTokenUser, pk=pk)
tokens_page_manager = page.tokenspagemanager.all()
data = {}
for token_page_manager in tokens_page_manager:
page_access_token = token_page_manager.pageaccesstoken.page_access_token
try:
graph = facebook.GraphAPI(page_access_token)
graph.get_object('me')
except facebook.GraphAPIError:
token_page_manager.delete()
data['error_token'] = 'Token Lỗi, Có Token bị die, load lại page bạn nhé!!'
break
if request.method == "POST" and request.is_ajax():
try:
_ = requests.get(REMOTE_SERVER, timeout=TIME_OUT)
list_conversations = request.POST.get('list_conversations_id').split("\n")
list_conversations = list(filter(None, list_conversations))
list_conversations = [i.strip() for i in list_conversations]
settings = {
'delay_time': int(request.POST.get('delaytime')),
'day_between': int(request.POST.get('daybetween')),
'list_conversations': list_conversations
}
data['settings'] = settings
except requests.ConnectionError:
data['error_connection'] = 'Lỗi kết nối'
return JsonResponse(data)