js键值对(字典)转json

$('#sub_btn').click(function () {
var user = $('#telephone').val();
var pwd = $('#password').val();
var send_data = {};
send_data["user"] = user
send_data["pwd"] = pwd
$.ajax({
    url: 'http://127.0.0.1:8000/user/login/',
    data: send_data,
    type: "POST",
    dataType: 'json',

其实这样后端接收到的是bytes

print((type(request.body)))
request_data = str(request.body,encoding='utf8')
print(request_data)

输出:


user=66&pwd=333

输入框里的数值是

user 66
passwd 333

加入

send_data = JSON.stringify(send_data)

后,

后端输出:


{"user":"55","pwd":"333"}

你可能感兴趣的:(前端开发,json)