Need Ajax Help: Targeting Specific Methods

Discussion in 'Javascript' started by pbd22, Mar 11, 2007.

  1. pbd22

    pbd22 Guest

    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.
    pbd22, Mar 11, 2007
    #1
    1. Advertising

  2. pbd22

    RobG Guest

    On Mar 12, 9:55 am, "pbd22" <> wrote:
    > 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.


    --
    Rob
    RobG, Mar 12, 2007
    #2
    1. Advertising

  3. pbd22

    pbd22 Guest

    On Mar 11, 9:13 pm, "RobG" <> wrote:
    > On Mar 12, 9:55 am, "pbd22" <> wrote:
    >
    >
    >
    > > 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.
    >
    > --
    > Rob



    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);
    }
    pbd22, Mar 12, 2007
    #3
  4. pbd22

    Darko Guest

    On Mar 12, 5:18 pm, "pbd22" <> wrote:
    > On Mar 11, 9:13 pm, "RobG" <> wrote:
    >
    >
    >
    > > On Mar 12, 9:55 am, "pbd22" <> wrote:

    >
    > > > 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.

    >
    > > --
    > > Rob

    >
    > 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.
    Darko, Mar 12, 2007
    #4
  5. pbd22

    pbd22 Guest

    On Mar 12, 10:36 am, "Darko" <> wrote:
    > On Mar 12, 5:18 pm, "pbd22" <> wrote:
    >
    >
    >
    > > On Mar 11, 9:13 pm, "RobG" <> wrote:

    >
    > > > On Mar 12, 9:55 am, "pbd22" <> wrote:

    >
    > > > > 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.

    >
    > > > --
    > > > Rob

    >
    > > 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.



    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.
    pbd22, Mar 13, 2007
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Frances Valdes

    Targeting a frame on page load

    Frances Valdes, Oct 6, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    348
    =?Utf-8?B?Q2h1Y2sgSGFlYmVybGU=?=
    Oct 6, 2004
  2. Stephen
    Replies:
    3
    Views:
    1,065
  3. Replies:
    2
    Views:
    633
  4. Replies:
    1
    Views:
    359
    David Dorward
    Nov 16, 2005
  5. Replies:
    2
    Views:
    84
    Dr John Stockton
    Nov 17, 2005
Loading...

Share This Page