我正在使用 apache tomcat 作为 Web 服务器。我已经在 tomcat 上部署了 web 服务。如果我通过 jquery ajax 从本地文件系统向 tomcat webservice 发布请求作为响应,我会收到 403 错误。
如果我从同一个容器运行相同的脚本,我将从 web 服务获得有效的响应。
我正在使用以下代码。
function callservice()
{
jQuery.support.cors = true;
var mobNo = document.getElementById('mobileNo').value;
var acctNo = document.getElementById('accountNo').value;
//var id = document.getElementById('id').value;
var custNo = document.getElementById('customerId').value;
//var mobNo = document.getElementById('txt_name').value;
//alert("mobileNo" + mobNo+"accountNo" + acctNo+"customerId "+custNo);
var url = "http://localhost/mobile-services/rest/user/";
var dataVal = {};
dataVal["mobileNo"] = mobNo;
dataVal["accountNo"] = acctNo;
dataVal["customerId"] = custNo;
var forminput = JSON.stringify(dataVal);
$.ajax({
url: url,
type: "POST",
data:forminput,
processdata: true,
contentType: "application/json;",
beforeSend: function () { },
headers :
{
"Content-Type" : "application/json",
"Accept" : "application/json"
},
success: function (data)
{
if (data.authenticated==true)
{
window.location.replace("http://localhost:8080/mobile-services/selected_services.jsp?userId="+data.id);
}
},
error: function (XMLHttpRequest, textStatus, errorThrown)
{
try
{
alert(JSON.stringify(XMLHttpRequest) + "\n" + textStatus + "\n" + errorThrown);
}
catch (ex) { alert("Exception occured.. "); }
finally { }
}
});
}
请建议。