http://blog.csdn.net/yiifaa/article/details/73468001
[url]http://www.cnblogs.com/Benoly/p/4341272.html
[/url]
var data = {
name : 'yiifaa'
};
// Submit data
$.ajax('app/', {
method:'POST',
// Encode data into form mode
contentType:'application/x-www-form-urlencoded; charset=UTF-8',
// The data must be a JS object, not a string
data : data,
success : function(datas) {
console.log(datas)
}
})
and the implementation of the Payload submission method is as follows:
$.ajax('app/', {
// According to my tests, the payload can only be used in the POST method
method: 'POST',
// The data type must be a type other than application/x-www-form-urlencoded
contentType:'application/json;charset=utf-8', charset=UTF-8',
// data must be converted to string
data : JSON.stringify(data),
success : function(datas) {
console.log(datas )
}
})
Conclusion
Although both Form submission and Payload can submit data, their application scenarios are quite different, and it is necessary to accurately understand their differences to be the prerequisite for proper application.
-------------jsonp save session across domain jquery
$.ajax({
url: 'http://localhost:8081/sms/authority/SignIn',
type: 'POST',
data: JSON.stringify({account: username, password: password}),
dataType: 'jsonp',
contentType:'application/json;charset=utf-8',
processData: false,
crossDomain: false,
xhrFields: {
withCredentials:
},
success: function(result){
if(result.success && result.result){
location.href= 'index.html';
}
},
error: function(error){
var errorResult = error.responseJSON;
var errorText = '用户名或密码不正确';
if(errorResult.result.message){
errorText = errorResult.result.message;
}
$('#errorMsg').html(errorText);
}
});
ajax request payload payload (Payload)
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=326558527&siteId=291194637
Ranking