1

This may sound silly, but I'm stuck trying to get the value from an ajax response.

I have a dummy.php file which just echoes "hello world" and I'm making an ajax request to get the text and console.log it.

My code is:

$(function(){
    console.log( getResponse() );
})

function getResponse(){
var request = $.ajax({
    url: "dummy.php",
    type: "POST"
});

request.success(function(data, textStatus, jqXHR){
    // part i'm missing
});

return return_value_from_the_dummy_file;
}

And I want the getResponse function to return the response text or in case of an error some text I'll set later.

What should I do?

ppp
  • 2,035
  • 9
  • 32
  • 52
  • 4
    You need to pass in a callback function to handle the results. Please refer to this thread: http://stackoverflow.com/questions/5316697/jquery-return-data-after-ajax-call-success – zxqx Feb 20 '13 at 22:58
  • @ZakAngelle thank you, this thread has very helpful information, this question is indeed a differently formatted duplicate of that thread. – ppp Feb 20 '13 at 23:02

0 Answers0