Identify Ajax proc name from a string variable

H

Hoss

Hello all-

The best way to describe what im trying to accomplish is with a code
snippet. Im using the free .NET ajax library.

<script language='javascript'>
function proc1()
{
myFunc("MyCodeBehind.MyAjaxProc");
}
function myFunc(procName)
{
procName("My Parameter", processMyFunc);
}
function processMyFunc(response)
{
// Process response from the server
}
</script>

So im essentially invoking an Ajax function , but I cant explicitly use
the name of it like so

MyCodeBehind.MyAjaxProc("My Parameter", processMyFunc);

That line would work fine. Clearly though, this doesnt work

var procName = "MyCodeBehind";
procName("My Parameter", processMyFunc);

If anyone knows how to accomplish this, im dyin to know!
 
T

Thomas 'PointedEars' Lahn

Hoss said:
[...]
<script language='javascript'>

function proc1()
{
myFunc("MyCodeBehind.MyAjaxProc");
}
function myFunc(procName)
{
procName("My Parameter", processMyFunc);
}
function processMyFunc(response)
{
// Process response from the server
}
</script>

So im essentially invoking an Ajax function , but I cant explicitly use
the name of it like so

MyCodeBehind.MyAjaxProc("My Parameter", processMyFunc);

That line would work fine. Clearly though, this doesnt work

var procName = "MyCodeBehind";
procName("My Parameter", processMyFunc);

If anyone knows how to accomplish this, im dyin to know!

Global functions are methods of the Global Object.
In global context, `this' refers to the Global Object.

this[procName]("My Parameter", processMyFunc);


PointedEars
 
H

Hoss

Alright - figured out the best way to do this.

var string = "var response = MyCodeBehind.MyAjaxProc('my parm')";
eval(string);
// do whatever with response variable

Why didnt I ever think of that =p
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top