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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:56:00+00:00 2026-06-02T17:56:00+00:00

I use ajax to retrieve a partial HTML document to use as a Knockout

  • 0

I use ajax to retrieve a partial HTML document to use as a Knockout template.

HTML:

<script type="text/html" id="LoadingTemplate">Loading...</script>
<script type="text/html" data-bind="attr: {'id': DynamicTemplateID}, html: ContentHTML></script>

<div class="main-page" data-bind="template: TemplateID"></div>

Script (partial):

self.TemplateID = ko.observable("LoadingTemplate");
self.DynamicTemplateID = ko.observable(GenerateUUID());

self.ContentHTML = ko.observable();    
ko.computed(function () {
    var url = self.ContentURL();
    self.GetContent(url, function (html) {
        self.ContentHTML(html);
        self.TemplateID(self.DynamicTemplateID());
    });
});
  1. Initially the <div> will show: ‘Loading’
  2. The id attribute of the dynamic template is set to the generated ID
  3. GetContent() performs an ajax call to retrieve the content
  4. When the ajax call finishes the callback function is called
  5. The observable ContentHTML is updated with the html
  6. The observable TemplateID is set to the generated ID
  7. The <div> is updated by ko

In Firefox this works like a charm, but IE8 throws an exception: Error: Unexpected call to method or property access. while updating the dummy <script> tag with the loaded template.

The error is throw by jQuery.html(). First elem.innerHTML = value; fails, which is catched then this.empty().append( value ) fails, which gives the exception.

Partial ‘stack trace’:

this.appendChild( elem );    => callback function in jquery.append (v1.7.2 line 5847)
jquery.domManip
jquery.append
jquery.html
ko.utils.setHtml
ko.bindingHandlers.html.update
ko.applyBindingsToNodeInternal
ko.dependentObservable.evaluateImmediate

What could be the problem? Is it there a (known) IE8 problem with updating <script> tags?
Is there another way to ‘store’ templates inside the html page for ko to use (I prefer to use the ko native templating!)?

  • 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-02T17:56:02+00:00Added an answer on June 2, 2026 at 5:56 pm

    I’ve solved it using this article on knockmeout.net:

    Updated HTML (removed the dynamic <script> tag):

    <script type="text/html" id="LoadingTemplate">Loading...</script>
    <div class="main-page" data-bind="template: TemplateID"></div>
    

    Updated script (appends the script tag after download of the template):

    self.TemplateID = ko.observable("LoadingTemplate");
    self.dynamicTemplateID = GenerateUUID();
    
    ko.computed(function () {
        var url = self.ContentURL();
        self.GetContent(url, function (html) {
            $("body").append('<script type="text/html" id="' + self.dynamicTemplateID + '">' + html + '</script>');
    
            self.TemplateID(self.dynamicTemplateID);
        });
    });
    

    This is a little bit less the ko-way but works across all browsers.

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

Sidebar

Related Questions

I use $.post('ajax/test.php', function(data) { $('.result').html(data);}); to send data and retrieve information and show
I use JQuery AJAX to retrieve some data (title and description). As you can
I have many forms that use AJAX (w/ jQuery) for validation and data submission.
I use the following AJAX request to retrieve a number of pages, whose titles
I'm using ajax to retrieve some data from the backend. I get the result
I have tried to use the following code to retrieve the data from the
I use an ajax call to retrieve a div that I want to prepend
I have the following script element in my web page: <script src=default.js type=text/javascript></script> Using
I have datestring =name=one $.ajax({ type: POST, url: 'url.com', data:datastring, complete: function(data){ alert(data); }
I tried to use standard ajax method, to retrieve page content from an URL,

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.