I want to call my rest web service from ajax. Url for my service is 'https://scv-dev.com/cdcAug/surveys/surveyData'. Iam able to call this service from rest client (firefox browser) but when am trying to call from ajax am getting error.
Ajax call :
$.ajax({ type: "POST", url: "https://scv-dev.com/cdcAug/surveys/surveyData", data: JSON.stringify({surveyId:1}), dataType: "json", headers: { Accept: "application/json", "Access-Control-Allow-Origin": "*" }, success: function (data) { alert(1); }, error: function (jqXHR) { alert(2); } }); Below is code for webs service :
@RequestMapping(value = "/surveyData", method = RequestMethod.POST, headers = "Accept=application/json") public @ResponseBody SurveyDataResponse getSurveyData(@RequestBody SurveyResApp surveyResApp, final HttpServletResponse httpResponse) { .............. }
$.ajax?console.info()in your jquery code and debug your code. You can have look at this link for more info about debugging.