0

I have a javascript array that holds a couple of ids. I want to send it to a rest webservice that I have written. Here is the code that I have for that -

$.ajax({
        type : 'GET',
        url : 'http://localhost:portNo/GlassdoorWebProject/index/getJobsData/list/',
        crossDomain : true,
        data : JSON.stringify(allIds),
        contentType: "application/json",
        success : function(data){
            alert("success in call2");

        },
        error : function(XMLHttpRequest,textStatus, errorThrown) {     
          alert("error"); 


        }
    });

When I execute this code I am getting an alert box that says error. This is how the method in my web service looks like -

@RequestMapping(value = "/getJobsData/list/{ids}", method = RequestMethod.GET)
public List<JobDetails> getJobs(@PathVariable("ids") String jobIds) {
    System.out.println("ids"+jobIds);
    return jobService.getJobDataForIds(jobIds);
}

When I run the it in a browser with the url in the browser it works. But when I run it through the code it does not work. Any suggestions?

3
  • 1
    What's the error? And generally you should POST not GET to send data back to the server Commented Aug 12, 2014 at 19:54
  • You can't send it as data. You need to append allIds to the url. Commented Aug 12, 2014 at 19:54
  • Other than using a GET instead of a POST or PUT, the code fragment looks fine. Commented Aug 12, 2014 at 20:33

1 Answer 1

1

Use this code snippet

@RequestMapping(value = "/getJobsData/list/", method = RequestMethod.GET)
public List<JobDetails> getJobs(@RequestParam("ids") String jobIds) {
    System.out.println("ids"+jobIds);
    return jobService.getJobDataForIds(jobIds);
}

the main problem is that you are sending the ids as the request parameters, but your are looking the values from the url. So i changed the code of your web service and i think it will solve your problem.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.