APIM HTML Response is not working in SPA

hampton123 1,175 Reputation points
2023-08-05T18:09:33.7+00:00

I'm working on an Azure Function hosted in APIM and using a Single Page Application (SPA) hosted in my storage account to let users log in via B2C. Users press a "Call API" button after logging in, which clears the previous content on the page and loads the home page I created in HTML from the API response. However, the download and upload buttons on the homepage are not working. The code below is the code that clears out the previous content of the page and loads in the html home page from my Azure Function in APIM (my home page with the upload and download buttons).

document.body.innerHTML = "";
document.body.innerHTML = await response.text()

For reference, the response in this case is the HTML page from the Azure Function. Can someone help me resolve this issue?

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
2,375 questions
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,711 questions
0 comments No comments
{count} votes

Accepted answer
  1. Sedat SALMAN 14,160 Reputation points MVP
    2023-08-05T18:58:22.2733333+00:00

    actually, since we do not know the code you are using i can just offer some alternative approach

    document.body.innerHTML = "";
    document.body.innerHTML = await response.text();
    
    
    let uploadButton = document.getElementById('upload-button');
    uploadButton.addEventListener('click', function() {
      // your code here
    });
    
    
    

    it may be related to the script that should be bound to

    or

    document.body.innerHTML = "";
    document.body.insertAdjacentHTML('afterbegin', await response.text());
    

    or you can write a script

    that adds HTML tags first and javascript tags later


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.