因为后端需要json或raw格式数据,按照网上的例子,发送的总是form-data数据
设置contentType:"application/json; charset=utf-8"后发现发送的不是POST请求,而是OPTIONS请求
$(document).ready(function(){
$("button").click(function(){
$.ajax({
type: "POST",
url: "http://121.45.108.14:8000/weiapi/login",
async: true,
data: JSON.stringify({
phone: "18625531123",
password: "74c665982bb15059e63"
}),
contentType: "text/plain; charset=utf-8",
dataType: "json",
success: function(data) {
}
});
});
});
向页面发送 HTTP POST 请求,并获得返回的结果
服务器端需要添加头 Access-Control-Allow-Origin:* 表示允许跨域访问