苗火 Nicholas
[JS]Object and String in ajax function
2016-11-2 萧


The difference between json object and json string while post with ajax:






var login = function(){
var user = $("input[name=username]").val();
var password = $("input[name=password]").val();

var data = {
username:user,
password:password
};
data = JSON.stringify(data);
console.log(data);
$.post(url_login, data, function(ele, status){
console.log(ele);
console.log(status);
});
}


Attention the command:



"data = JSON.stringify(data)"



It will post the data as normal request values if you didn't change data into a string in the function post. Otherwise as input stream.

发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容