Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

127
Views
How to call a promise function which will load content on a page dynamically?

I want to load dynamically content on my page using promise in javascript.

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8"/>
        <title>Main</title>
        <script type="text/javascript">

            function func(url){
                return new Promise(function(resolve, reject) {
            
                    var request = new XMLHttpRequest();
                    request.open('GET', url);
                    request.onload = function() {
                        if (request.status == 200){
                            resolve(request.response);
                        } else {
                            reject(Error(request.statusText));
                        }
                    };
            
                    request.onerror = function() {
                        reject(Error("Network Error"))
                    };
            
                });
            }

            $(document).ready(function() {
                func('hello.html');
            });

        </script>
    </head>
    <body>
        
    </body>
</html>

I have hello.html file in the same folder and want to load it using func(). Is it the correct way to do it?

about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!