Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8135071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:17:07+00:00 2026-06-06T10:17:07+00:00

I have two Ajax calls. I need to make sure that a JS function

  • 0

I have two Ajax calls. I need to make sure that a JS function is executed between these two calls.

Is it possible to trigger the execution of a client-side JS function via the AJAX response? Or how would you do this kind of thing?


EDIT My code, after doing what was suggested by the first answer (onComplete):

^ (html jQuery ajax
    callback: [ :text | id := self createNewAnnotation: text ]
    value: (self html jQuery: '#annotationText') value;

    onComplete: ((JSStream on: 'displayAnnotation("', id, '")'), 
        (self html jQuery ajax
            callback: [ :text | finalText := text ]
            value: (self html jQuery: '#text') html)
    );

What this is supposed to do: on the first callback, the value of the #annotationText field is passed to createNewAnnotation, which saves the annotation and returns the ID.
Next, I want to pass that ID to the client-side JS function displayAnnotation().

In this example, this can’t yet work, as the code around JSStream on: is not in a block and thus has the initial value of id. How can I pass that result of the server-side method as parameter to the client-side function?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T10:17:10+00:00Added an answer on June 6, 2026 at 10:17 am

    In Seaside, you probably would use the jQuery bindings to execute ajax calls. If you want to make sure that two ajax calls are chained and some other JS code is executed in between, the code would follow these lines:

    renderContentOn: html
        html span
           onClick: (html jQuery ajax 
                        callback: [...1st ajax callback...];
                        onComplete: ((JSStream on: '... some JS code ...'),
                                     (html jQuery ajax callback: [...2nd ajax callback...]));
           with: 'Click this to trigger the calls'.
    

    This will render a span that, when clicked, will execute the 1st ajax call. If that one completes, the JS code and the second ajax call will be executed.

    EDIT:answer to the additional question:

    If you want the ‘id’ that is passed on to the call of displayAnnotation to be computed by the first callback, you can only generate that call after the first callback has executed. The value can be passed between ajax callbacks via temporary variables or instance variables (because of closures). The following piece of code makes the chaining via onComplete: explicit. Afterwards, I give an example where less ajax calls are made.

    ^ (html jQuery ajax
        callback: [ :text | id := self createNewAnnotation: text ]
        value: (html jQuery: #annotationText) value;
        onComplete:  
            (html jQuery ajax 
                  script:[:s | s << ((JSStream on: 'displayAnnotation("', id, '")')]
                  onComplete:
                      (html jQuery ajax 
                           callback: [ :text | finalText := text ]
                           value: (html jQuery: #text) html)))
    

    You can also reduce the number of ajax calls if you understand how Seaside callbacks work. In summary, the block that produces the response of the callback is always invoked last. This allows to group a number of callback blocks in a single call. Such as:

        ^ (html jQuery ajax
              callback: [ :text | id := self createNewAnnotation: text ]
              value: (html jQuery: #annotationText) value;
              script:[:s | s << ((JSStream on: 'displayAnnotation("', id, '")')];
              onComplete:
                      (html jQuery ajax 
                           callback: [ :text | finalText := text ]
                           value: (html jQuery: #text) html)))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a event handler which makes two AJAX calls to the server:
I have two application that need to talk to each other. App1 needs to
I have customized a plugin to make some ajax calls to admin-ajax.php and it
I have two buttons, and their click events perform an ajax operation. I need
I have two ajax calls, but for some reason one of the ajax isn't
In an MVC3 application I have a view rendering two Ajax partial views: a
I have two methods -a and -b. -a calls sometimes -b, and -b sometimes
I have some ajax calls in multiple JavaScript functions. Each one does a post
I have two validation jQuery functions which I need to fire one after another.
I have two MySQL tables named 'nodes' and 'joinTable' like shown below. I need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.