Need Ajax Help: Targeting Specific Methods

P

pbd22

Hi.

I have an ajax question.
I am wondering if it is possible to get the response from a method
within a given page, and that function alone? Traditionally, I have
been getting the response from the Page_Load method of the targeted
page, but now I want the response from a particular method on the
target page:

Public Sub SomeCallback(ByVal sender As Object, ByVal e As EventArgs)

'RETURN XML FOR CALLBACK

End Sub

Could somebody tell me how to focus on the resonse of a given method
inside a page? Thanks.
 
R

RobG

Hi.

I have an ajax question.
I am wondering if it is possible to get the response from a method
within a given page, and that function alone? Traditionally, I have
been getting the response from the Page_Load method of the targeted
page, but now I want the response from a particular method on the
target page:

Public Sub SomeCallback(ByVal sender As Object, ByVal e As EventArgs)

'RETURN XML FOR CALLBACK

End Sub

Could somebody tell me how to focus on the resonse of a given method
inside a page? Thanks.

Events are fired by DOM elements (e.g. load event when the document
has finished loading), javscript functions don't have any such
concept.

If you want something to happen when a function is called, either have
the function call the method or wrap the function in some other method
and call your "event" function straight after the one you want to
watch.
 
P

pbd22

Events are fired by DOM elements (e.g. load event when the document
has finished loading), javscript functions don't have any such
concept.

If you want something to happen when a function is called, either have
the function call the method or wrap the function in some other method
and call your "event" function straight after the one you want to
watch.


Thanks.

Maybe I misunderstand what you are saying, but, I still don't
understand how to call a server method from the client-side
ajax call. would you mind showing me how to solve this problem? For
example, for the below ajax call, I am getting the response from the
Server.aspx pages's Page_Load method. But, how would I design the
below function to get the response from the server's SomeCallback
method?

function startRequest() {
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
} else if (window.ActiveXObject) {
isIE = true;
req = new ActiveXObject("Microsoft.XMLHTTP");
}
req.open("GET", "server.aspx", true);
}
 
D

Darko

Thanks.

Maybe I misunderstand what you are saying, but, I still don't
understand how to call a server method from the client-side
ajax call. would you mind showing me how to solve this problem? For
example, for the below ajax call, I am getting the response from the
Server.aspx pages's Page_Load method. But, how would I design the
below function to get the response from the server's SomeCallback
method?

function startRequest() {
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
} else if (window.ActiveXObject) {
isIE = true;
req = new ActiveXObject("Microsoft.XMLHTTP");
}
req.open("GET", "server.aspx", true);

}

Provide the script with a url parameter inside your ajax request, and
the script should call the proper method depending on this parameter.
You can't interfere with the work of your server script from inside
JavaScript. To ajax, i.e. to http protocol, all you're requesting is
the result of a program. What that program does is irrelevant for it,
as long as it gets the proper result. However, you can provide it with
parameters based upon which the server script can decide what methods
it's going to call.
 
P

pbd22

Provide the script with a url parameter inside your ajax request, and
the script should call the proper method depending on this parameter.
You can't interfere with the work of your server script from inside
JavaScript. To ajax, i.e. to http protocol, all you're requesting is
the result of a program. What that program does is irrelevant for it,
as long as it gets the proper result. However, you can provide it with
parameters based upon which the server script can decide what methods
it's going to call.


Thanks Darko (and Rob),

I think I understand. Not sure tho.

So, are you saying that if I include a parameter in the xmlhttp
request that points to the server-side method I will be able to target
that method's response? For example:

req.open("GET", "server.aspx?startMethod=SomeCallback", true);

This doesn't look right. Would somebody mind showing me a code example
of how to do this (your own code or a link)? Sorry, I just want to
make sure I understand this.

Thanks.
 

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
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top