I am using login webservices to validate the user.
These are spring 3.0 rest webservices designed in such a way that it accept only data with POST method.
I am able to send data to the webservices using GET.
But due to the webservices implementation I have to submit data using POST method.
If i use jquery ajax request with POST I am getting 403 Access forbidden error.
Below is the working example for GET request.
I am using CORS filter for tomcat to enable CORS support.
function callservice()
{
jQuery.support.cors = true;
var mobNo = document.getElementById('mobileNo').value;
var acctNo = document.getElementById('accountNo').value;
var custNo = document.getElementById('customerId').value;
url = url+mobNo+"/"+acctNo+"/"+custNo;
$.getJSON(url,
function(data)
{
if (data.authenticated==true)
{
alert("data "+data);
}
});
}
But if i use following code i am getting 403 error.
function callservice()
{
jQuery.support.cors = true;
var mobNo = "123123123";
var acctNo = "123123123";
var custNo = "123123123";
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,
datatype:"jsonp",
crossDomain: true,
contentType: "application/json",
beforeSend: function () { },
headers :
{
"Content-Type" : "application/json",
"Accept" : "application/json",
"Origin" : "http://localhost/",
"Access-Control-Allow-Origin" : "*"
},
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 suggest.