Tuesday 28 March 2017

javascript - jquery - return ajax response value

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?

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...