canpoint
canpoint

Reputation: 859

return value of the function that is called in ajax process

Am I able to access return value of the function that is called in ajax process(url given) inside success? For example, I am calling export() function in ex.php (url:ex.php) and that function return me the name of the exported file. I want to access this filename in ajax succes. (success:)

Thanks.

Upvotes: 0

Views: 1619

Answers (2)

masnun
masnun

Reputation: 11906

You have to echo the value from the php script. Like -

<?php echo export(); ?>

Now inside Ajax success(), you can just grab the ajax response to get the value.

$.ajax({
  url: 'ex.php',
  success: function(data) {
    alert("Exported file name: " + data);
  }
})

Or even simpler version -

$.get("ex.php", function(data) {
  alert("Exported file name: " + data);
})

Upvotes: 2

Alex Mcp
Alex Mcp

Reputation: 19315

Sure, it's passed to the function you set as the success handler:

$.ajax({
  url: 'myUrl.com',
  success: function(data) {
    console.log(data); //shows data returned from server
  }
})

Upvotes: 1

Related Questions