我有大量用户要传递到Django项目的后端。我创建一个[帐户,用户名,密码]的列表。然后,我也尝试将其后端通过ajax发布。我似乎无法弄清楚该怎么做。
这是我的[帐户,用户名,密码]创建代码列表:
function get_all_usernames_and_password(){
var account_list = [];
$('.card').each(function(e){
var account = [];
account.push($(this).find('.name').val());
account.push($(this).find('.username').val());
account.push($(this).find('.password').val());
if(account[0] != null){
account_list.push(account);
}
})
return account_list;
}
然后我尝试制作一个帖子列表,这样:
$('#submit').on("click",function(e){
var ready_to_submit = true;
if(!tag_count_check()){
ready_to_submit = false;
}
if(!agreed_to_terms()){
ready_to_submit = false;
}
if(ready_to_submit){
e.preventDefault();
var account_info_json = JSON.stringify(get_all_usernames_and_password());
$.ajax({
type:'POST',
url:'/create_new_group/create_group/',
data:{
csrfmiddlewaretoken:$('input[name=csrfmiddlewaretoken]').val(),
account_info: account_info_json,
} ,
success:function(data){
if(data.status == 1){
//success!
console.log('Success!')
}
else if(data.status == 2){
//failed
console.log('Failed!')
}
}
});
}
});
然后后端打印(json.dumps(request.POST)),这就是我得到的:
{"csrfmiddlewaretoken": "11vuGHM52Fyag8qBrv6nJdCRR92uCLPuwP7M8qE1vLeaA5gVVOSCc2G0tE3MZsiD", "account_info": "[[\"1111\",\"1111\",\"11111\"],[\"2222\",\"2222\",\"2222\"]]"}
它不会让我像json对象一样访问它。我在做什么错了?