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 7675625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:00:09+00:00 2026-05-31T17:00:09+00:00

I am new to javascript and the whole front-end side of development. Here is

  • 0

I am new to javascript and the whole front-end side of development.

Here is what I am using:

  • Java servlet running on Tomcat7
  • twitter-bootstrap for the layout/theme
  • Pubnub to keep track of how many times a form is submitted
  • Javascript/jquery to display this value on a webpage.

I have added the PUBNUB.subscribe callback which updates the value on the webpage just fine. However, when I first load the webpage, I don’t know what value I should display.

Here is what I did to overcome this issue:
I added a method to the servlet that, when passed in the correct parameter in a POST request, it will send out a pubnub message with the amount to be displayed which is working fine.

Next, I tried to call a POST request using jquery like this:

$.post("../servlets/theservlet",
        {
            update : "true"
        });

I tried placing that inside a $(window).load function but when I loaded the webpage, it did not do what I expected.
I expected it to do the POST after everything was loaded, which would cause the pubnub message to be published from the servlet, which would activate the callback method in the PUBNUB.subscribe function. However, the value didn’t change, it stayed as the placeholder that is hardcoded in the html.

Currently, I am now calling setTimeout(“updateUses()”, 1500); from within the $(window).load function. updateUses() is the exact same $.post call I showed earlier.

Now when I load the page, the placeholder value is there for a little bit (seems longer than 1.5ms) and then it is updated to the correct value. If I remove the setTimeout and just call updateUses() directly, then nothing happens again.

What do I need to change so that it loads the value instantly (or at least without a noticeable delay)?

  • 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-05-31T17:00:10+00:00Added an answer on May 31, 2026 at 5:00 pm

    If the page builder is JSP and what I have just read is correct then you should be able to do something like this:

    RequestDispatcher rd=application.getRequestDispatcher("path/to/pubnub/servlet");
    rd.include(request,response);
    

    If you choose to stick with the ajax approach then the javascript should look something like this:

    $(function(){
        $.post("path/to/pubnub/servlet", {update:"true"}, function(response){
            //do whatever is necessary with the response here, eg.
            //$("#myElementId").html(response);
        });
    });
    

    The $(function(){...}) wrapper ensures the code inside it is executed at the earliest opportunity after the DOM becomes ready. Hence no need for a timeout. jQuery is typically written inside such a wrapper.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Yo. I'm really quite new to this whole JavaScript business, not to mention AJAX,
I'm using Nodejs and Socket.io. When the client connects, new JavaScript objects are created.
New to javascript/jquery and having a hard time with using this or $(this) to
I've recently written a javascript RegExp to cleanse my data at the front end,
I am new on development of Blackberry playbook apps. Can we develop whole apps
I'm very new with javascript. I'm trying to create a tag using document.write (with
The tutorial is here: Tutorial: Writing Spreadsheet data using JavaScript Objects The full code
I'm brand-spanking new to the whole stack - javascript, node.js, coffeescript, nodeunit. Think I
I'm new at javascript and while there are many more complex solutions, I don't
New to javascript, but I'm sure this is easy. Unfortunately, most of the google

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.