⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

What is callback function in javascript



Sudesh Nair
  • profile picture
  • Member

Posted 13 October 2012 - 07:40 AM

i m lil bit confuse with the concept of [color=#ff0000]callback function[/color]. any one here who can make me understand the concept of [color=#ff0000]callback function[/color]. pls give me one simple example too...

victor
  • profile picture
  • Member

Posted 14 October 2012 - 06:20 AM

HI! You can read about callback function here http://en.wikipedia.org/wiki/Callback_(computer_programming).

victor
  • profile picture
  • Member

Posted 14 October 2012 - 07:29 AM

new Ajax.Request('http://example.com/do_it',
{
method: 'post',
onSuccess: function(transport) { // callback function (if request is successful).
window.alert("Done!"); //
}, //

onFailure: function() { // callback function
window.alert("Error!"); // if request is unsuccessful
}
});