I am using apache tomcat as a web server. I deployed webservices on tomcat. If I send a request via jquery ajax from the local file system to tomcat webservice in response, I get 403 error.
If I run the same script from the same container, I get the correct response from webservice.
I am using the following code.
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 { } } }); }
Please offer.
jquery ajax web-services tomcat
Chetan shirke
source share