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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:43:52+00:00 2026-05-22T02:43:52+00:00

I develop a web application that is getting user updates from a web service

  • 0

I develop a web application that is getting user updates from a web service (that is in another domain) I want to get the updates every 10 seconds.

For calling the service for the first time I dynamically insert a script in the page. The service is JSONP. Then I would like to define a trigger that insert a script from 10 to 10 seconds to get the updates. Is this correct? Can I do that without affecting the user experience on the website? I mean the site performance … it will be great if I could do the call async and when I have the results I will update the status.

Is there any better solution for accessing the remote services. Is there an efficient way of dynamically reusing the same script using a trigger? I am pretty new to Javascript. Can you give me a short sample how can I define a trigger that calls a remote web service? … or if there is a better solution.

  • 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-22T02:43:53+00:00Added an answer on May 22, 2026 at 2:43 am

    The following will dynamically create the script tags, and delete them (and the global it requires) after being finished with a given call.

    You could also use CORS to allow requests besides GET ones, though as you may be aware, that is not supported in older browsers.

    To avoid race conditions or performance problems during a slow network, you could allow the JSONP callback to recursively call the function, thereby only making a new call if the callback was returned, though with an optional setTimeout call to ensure there is at least a minimum delay.

    The following uses Wikipedia’s API to grab a specific page revision and its user.

    <script>
    var JSONP = function(global){
        // (C) WebReflection Essential - Mit Style ( http://webreflection.blogspot.com/2011/02/all-you-need-for-jsonp.html )
        // 202 bytes minified + gzipped via Google Closure Compiler
        function JSONP(uri, callback) {
            function JSONPResponse() {
                try { delete global[src] } catch(e) { global[src] = null }
                documentElement.removeChild(script);
                callback.apply(this, arguments);
            }
            var
                src = prefix + id++,
                script = document.createElement("script")
            ;
            global[src] = JSONPResponse;
            documentElement.insertBefore(
                script,
                documentElement.lastChild
            ).src = uri + "=" + src;
        }
        var
            id = 0,
            prefix = "__JSONP__",
            document = global.document,
            documentElement = document.documentElement
        ;
        return JSONP;
    }(this);
    
    // Be sure to include the callback parameter at the end
    
    function startAPI (start) {
        start = start || new Date();
        var url = 'http://en.wikipedia.org/w/api.php?action=query&prop=revisions&titles=Main%20Page&rvprop=timestamp|user|comment|content&format=json&callback';
        var minimum = 10000;
        function execute (str) {
            alert(str);
        }
        JSONP(url, function (obj) {
            for (var pageNo in obj.query.pages) {
                var page = obj.query.pages[pageNo];
                var str = 'The user ' + page.revisions[0]['user'] + ' left the page with this code ' + page.revisions[0]['*'];
                execute(str);
                var elapsed = (new Date().getTime()) - start;
                setTimeout(startAPI, (elapsed < minimum) ? (minimum - elapsed) : 0);
                break;
            }
        });
    }
    startAPI(); 
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imagine that you want to develop a non-trivial end-user desktop (not web) application in
I want to develop a mobile web application using asp.net 3.5 that can be
I want to develop a web application in JSP ,in which a user can
I develop a web application that needs to be load balanced across 4 webservers.
I ask this because at work I am supposed to develop a web-application that
I'm starting to develop a web application in PHP that I hope will become
I have a Web Application that I'm trying to move from Sun Application Server
I am preparing to develop a web application that will (hopefully) be used by
I'm trying to develop a web application that mainly uses PHP but i'm using
I'd like to develop a web sample application that can send and read audio

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.