我正在使用AWS API并通过jQuery AJAX访问API,但是当我在使用JSON.stringify之后发送数据中的单个值时,数据就正确发送了,但是当我发送多个键和值时,我正在收到POST 400和Access-Control-Allow-Origin错误,这是我的代码
HTML
<input id="mnumber" type="text" placeholder="Mobile Number">
<input id="fname" type="text" placeholder="Full Name">
<input id="baddress" type="text" placeholder="Business Address">
<input id="pcode" type="text" placeholder="Pincode">
<input id="stateFieldI" type="text" placeholder="State">
<input id="bTypeFieldI" type="text" placeholder="Type of Outlet">
<input id="customerI" type="text" placeholder="Existing Customer">
<input type="submit" id="send" value="submit">
JS
$(document).ready(function(){
$('#send').click(function(){
$.ajax({
url: 'XXX',
type: 'POST',
crossDomain: true,
data: JSON.stringify({
mnumber: $('#mnumber').val(),
fname: $('#fname').val(),
baddress: $('#baddress').val(),
pcode: $('#pcode').val(),
stateField : $('#stateFieldI').val(),
bTypeField : $('#bTypeFieldI').val(),
customer : $('#customerI').val()
}),
headers: {
'X-Api-Key':'XXX'
},
dataType: 'json',
contentType: "application/json",
success: function (data) {
console.info(data);
}
});
});
});
对不起,我无法公开显示我的URL和X-API-Key,这就是为什么我添加了“ XXX”