当我对一台服务器进行ajax调用时,我有一个js。当我使用localhost调用此服务时,可以使用。但是,当我使用上传服务器的服务器调用此服务时,其错误500。调用返回json。
$.ajax({
url: "https://www.example.com/example",
dataType: "json",
data: {
'data': xml,
'message': message,
'customer_id': customer_id,
'subscr_id': subscr_id
},
type: 'POST',
success: function (devol) {
},
error: function (xhr, ajaxOptions, thrownError) {
alert("no ha entrado");
}
});
答案 0 :(得分:0)
尝试在下面更新您的代码:
var model = {
'data': xml,
'message': message,
'customer_id': customer_id,
'subscr_id': subscr_id
};
$.ajax({
url: "https://www.example.com/example",
type: 'POST',
dataType: 'json',
data: JSON.stringify(model),
//headers: { 'authorization': `Bearer ${token}` },
async: false,
processData: false,
contentType: "application/json",
error: function (err) {
},
success: function (data) {
}
});
答案 1 :(得分:0)
这可能是由于CORS(跨域资源共享)导致的。通常,除非您进行呼叫的其他域允许CORS到所有站点或特定站点,否则您无法从浏览器对其他域进行呼叫。