web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / Uncaught ReferenceErro...
Power Pages
Answered

Uncaught ReferenceError: webapi is not defined

(0) ShareShare
ReportReport
Posted on by 265

hi , 

I am getting this kind of error.

Erandi_1-1708576852668.png

the error is happened with below code. 

Erandi_0-1708576830929.png

Which kind of reasons are caused to above errors?

Thanks

Categories:
I have the same question (0)
  • Verified answer
    Lucas001 Profile Picture
    2,434 Super User 2025 Season 2 on at

    Hi @Erandi ,

     

    the issue is probably exactly what's stated.

    Did you initialize the webApi?

     

    Post the following script at the end of your html of the page you use the webapi in and it should work fine:

    <!--Script to make the webapi work-->
    <script>
     (function (webapi, $) {
     function safeAjax(ajaxOptions) {
     var deferredAjax = $.Deferred();
    
     shell.getTokenDeferred().done(function (token) {
     // add headers for AJAX
     if (!ajaxOptions.headers) {
     $.extend(ajaxOptions, {
     headers: {
     "__RequestVerificationToken": token
     }
     });
     } else {
     ajaxOptions.headers["__RequestVerificationToken"] = token;
     }
     $.ajax(ajaxOptions)
     .done(function (data, textStatus, jqXHR) {
     validateLoginSession(data, textStatus, jqXHR, deferredAjax.resolve);
     }).fail(deferredAjax.reject); //AJAX
     }).fail(function () {
     deferredAjax.rejectWith(this, arguments); // on token failure pass the token AJAX and args
     });
    
     return deferredAjax.promise();
     }
     webapi.safeAjax = safeAjax;
     })(window.webapi = window.webapi || {}, jQuery)
    </script>



    --------------------------------------------------------------------------------------

    Hope that helps.

    If the post solves your problem, please mark it as solution. If it helps, consider a thumbs up.

  • Erandi Profile Picture
    265 on at

    @Lucas001 It is worked thank  you very much

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Pages

#1
Fubar Profile Picture

Fubar 74 Super User 2025 Season 2

#2
Jerry-IN Profile Picture

Jerry-IN 55

#3
sannavajjala87 Profile Picture

sannavajjala87 31

Last 30 days Overall leaderboard