Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Using Passing Parameters -arguments- to OnSuccess Callback function in a Asp.Net Ajax

0.00/5 (No votes)
3 Aug 2010 1  
How to pass custom args to the OnSuccess callback function of javascript ajax

Introduction

This code snippet solves the problem of passing parameters to the callback OnSuccess or onreadystatechange functions used in javascript Ajax with or without Microsoft .Net framework

Background 

On many forums people ask how to do that. 

SOLUTION CODE

 Useful also in Asp.Net Ajax development environments (using integrated Microsoft Ajax).

    //Function to call when OnSuccess or onreadystatechange
    function yourCallBack(arg1,arg2) {
        return function(result) { // Your old function
            alert(arg1);  // param will be accessible here
            alert(arg2);  // param will be accessible here
            alert(result);// result = the response returned from Ajax
        }        
    }
		

Using the code

The solution is very simple and easy, try it .

Points of Interest 

Usefull for some complex scenarios that requires passing variables to the ajax delegate

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here