如何JSON格式发送到服务器

余万的数据是这种格式如何JSON格式发送到服务器

{"email":"[email protected]","password":"1"} 

但在这种格式

{ '{"email":"[email protected]","password":"1"}': '' } 

我的客户端代码获得,

headers.append('Content-Type', 'application/x-www-form-urlencoded') 

this.http.post(this.header1+'login', JSON.stringify(form), { headers: headers })

我我不知道这一点,可以在任何一个建议帮助请

我的后端代码,

exports.login = function(req, res) { 

console.log(req.body)

var query = 'select * from profile where email = ? and password = ?';

connection.query(query,[req.body.email,req.body.password],function(error,result,rows,fields){

if(!!error){console.log(error)

console.log('fail');

}else{

console.log(result);

res.send(result);

}

// }

});}

回答:

试试这个

$.ajax({ 

url: this.header1+'login',

data: {"email":"[email protected]","password":"1"},

type: 'POST',

success: function(response) {

alert(response);

}

});

回答:

如果你想使用jQuery的它很简单:

$.post('http://address', {"email":"[email protected]","password":"1"}).done((response) => { 

// Request complete

}).fail((jqXHR) => {

// Request failed

});

回答:

Try This 

$http({

url: this.header1 + 'login',

,

method: "POST",

data: {

"email": "[email protected]",

"password": "1"

},

headers: {

'Content-Type': 'application/json;',

'Access-Control-Allow-Origin': '*'

}

}).success(function (response) {

})

以上是 如何JSON格式发送到服务器 的全部内容, 来源链接: utcz.com/qa/261615.html

回到顶部