0

I'm tying to fetch some data from my database. When i give the path in my browser i can see the content but i want to get the data from by using ajax and store it in a variable.

function getSuccessOutput() {
$.ajax({
    url:'/dc/dcrest/dcrs/datacenter/1',
    complete: function (response) {
        $('#output').html(response.responseText);
    },
    error: function () {
        $('#output').html('Bummer: there was an error!');
    },
});
return false;

}

  • Possible duplicate of [How do I return the response from an asynchronous call?](http://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – freedomn-m Jun 27 '16 at 10:49
  • 1
    I don't understand the question. Does your code work? Is the URL valid? Are you asking about the difference between absolute vs relative URLs? – Tom Lord Jun 27 '16 at 10:50
  • Sounds like you're not returning html - so just `var result = response` should suffice. – freedomn-m Jun 27 '16 at 10:50
  • Yeah that code works. i tested it with files in the same directory. that url i have mention overthere is rest URI . It also works (tested with rest client) . but i want it with ajax :) @Tom Lord – sarma senagavaram Jun 27 '16 at 10:58
  • Im returning it to my html :) to one id @freedomn-m – sarma senagavaram Jun 27 '16 at 11:00
  • Not returning *to* - what's the content of "response"? If it's a REST URI then the result should not be html - so you shouldn't be doing `.html(response)` – freedomn-m Jun 27 '16 at 11:01
  • That URI is on local server. so do i require any server side script languages to get my data from database?? – sarma senagavaram Jun 27 '16 at 11:02
  • No - you get the "data" back when you enter the url in the browser, so there's nothing wrong with the server. – freedomn-m Jun 27 '16 at 11:02
  • $.ajax({ type: "POST", data :JSON.stringify($('form').serializeObject()), url: "http://localhost:8080/dc/dcrest/dcrs/datacenter/addDataCenter", contentType: "application/json" }); I tried this code at first Even this didnt work. – sarma senagavaram Jun 27 '16 at 11:07

0 Answers0