Ajax jquery call getting NetworkError: 403 Forbidden error in response
20,439
Because webserver is assuming it cross domain communication thats why you are getting 403.
You need to use JSONP for this
https://github.com/jaubourg/jquery-jsonp
basic usage.
$.jsonp({
var url = "abc.do";
success: function(jsonData, textStatus) {
$.jsonp({
url: url+"?callback=?",
success: function(jsonData, textStatus) {
},
error: function(xOptions, textStatus){
}
});
},
error: function(xOptions, textStatus){
}
});
Author by
Chetan Shirke
Updated on July 13, 2022Comments
-
Chetan Shirke almost 2 years
I am using apache tomcat as a web server. I have deployed webservices on tomcat. If i post request through jquery ajax from local file system to tomcat webservice in response i am getting 403 error.
If i run the same script from the same container i am getting valid response from the webservice.
I am using 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 suggest.
-
Chetan Shirke almost 12 yearsCan you please tell me how to use this plugin?
-
Zahid Riaz almost 12 yearsjquery4u.com/json/jsonp-examples/#.T-gsN7Ue4s4 This will explain all the details of how to use JSONP.