Reload Popup Box

I am currently developing a website using Django and I am in need of a popup window that can display logging messages and automatically refresh itself every N seconds. In order to achieve this, I am utilizing the standard Python logger, JavaScript, and Dajaxice for handling popups.

However, I have encountered a challenge in getting the popup to refresh automatically while utilizing the log file content retrieved within the Dajaxice function.

The code snippet from my ajax.py is as follows:

import json, SIMPLCode, logging, os, sys
from dajaxice.decorators import dajaxice_register

@dajaxice_register(method='GET')
def getLogs(request):
  fname = "SIMPLCode/Logs/LOG_2015-07-08.log"
  with open(fname,"r") as f:
    lines = f.readlines()
  lines = lines[-10:]
  return json.dumps({'logLines':lines})

This is what my proposed Django HTML markup looks like:

<button class="btn btn-primary" onclick="Dajaxice.InterfaceApp.getLogs(popitup())">{% bootstrap_icon "share-alt" %} View Log File </button>

Below is the sample JS code for reference:

function popitup(data) {
    $(document).ready(function(data) {
      var log_file = data.logLines;
      var newwindow=window.open('','Log Viewer','height=300,width=500');
      newwindow.write(log_file)
    });

    if(newwindow && !newwindow.closed){
      newwindow.location.reload(true); 
      newwindow.focus();
    } 
  }

Although, upon implementing the above solution, I encountered an error stating that the data from my dajaxice function is not defined:

Uncaught TypeError: Cannot read property 'logLines' of undefined

Interestingly, when I simplified things and used an alert window it worked fine:

<input id="LogMessages" type="button" value="View Log Messages" onclick="Dajaxice.InterfaceApp.getLogs(function(d){alert(d.message);})"/>

Given my limited experience with JS and dajaxice, I am finding it challenging to find resources online. Any assistance or guidance on resolving this issue would be greatly appreciated!

Answer №1

The issue arose from my method of calling it. The accurate way to do it is as follows:

<button class="btn btn-primary" onclick="Dajaxice.InterfaceApp.getLogs(popitup)">{% bootstrap_icon "share-alt" %} View Log File </button>

It was incorrect to have () after the call to popitup

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

To access JSON data in PHP, it is only possible from a remote URL and not from a locally hosted

Currently in the process of developing a website utilizing the Slim framework. I have successfully set up an endpoint on my site, which is functioning properly. However, when attempting to retrieve data using PHP file_get_contents() and json_decode(), noth ...

Retrieve user-specific relational data

In my Supabase database, I have three main tables: users, teams, and members. The users table stores information about all users who sign up using auth. Here are the details contained in this table: id displayname email 602eff1e-6300-491e-b821-44e ...

"Unleashing the power of infinite Ajax requests upon a drop change event in Knock

I am working with Knockout MVC on my current project and encountering an issue. Whenever I try to pass the viewModel when the Drop Down changes, the method call gets invoked multiple times and the alert message "ok" keeps popping up continuously. Can som ...

Guidelines for utilizing basepath for specific pages in NextJS

I'm currently working on a NextJS application using version 13 and I have a question regarding setting the basepath for specific pages only. For example: "/auth/*" --> should not display the basepath "/remaining-pages" --& ...

Exploring ways to loop through and update elements within a PostgreSQL JSONB array of objects

Looking to transform a jsonb array in PostgreSQL 12: [{"data":"42","type":"TEMPERATURE"},{"data":"1.1","type":"PRESSURE"}] The goal is to change it into: [{"data":&q ...

What could be the reason for my jQuery script not functioning properly?

<script> var currentLevel = 0; $(document).ready(function(){ $("#tolevel_" + (currentLevel+1) ).click(function(){ $("#level_" + currentLevel).hide(500,'swing', function(){ $("#level ...

The combination of Masonry, FlexSlider, and endless scrolling functionality creates a

I am currently using the Masonry layout and implementing infinite scroll functionality through a jQuery plugin. Within this content, I have various FlexSlider slideshows. Unfortunately, when I trigger the infinite scroll feature, the slider does not displa ...

Disabling dynamic color updates upon refresh

I am currently using chartjs and I want to generate new random colors each time the page is refreshed. However, I need these colors to remain fixed and not change after a page refresh or reload. Below is the function I am working with: getRandomRgb() { ...

What is the best way to test the Express router catch branch in this specific scenario with Jest?

My current task involves working with a file containing two routes. The first route is located in routes/index.js const express = require('express') const router = express.Router() router.get('', (req, res, next) => { try { r ...

Angular Js: Displaying JSON Object with Multiple Nested Layers

Looking for a way to display a menu using Angular and JSON object that utilizes ul and li. Trying to achieve this using ng-repeat, but encountering challenges when dealing with deeply nested objects. Here's the HTML code: <ul> <li ng-rep ...

Python: Storing data retrieved from AJAX response as a .json file and loading it into a pandas DataFrame

Greetings and thank you for taking the time to read this, My objective is to extract company information from a specific stock exchange and then store it in a pandas DataFrame. Each company has its own webpage identified by unique "KodeEmiten" endings, wh ...

How can we include parameters as key value pairs in a JSON resource for @ParameterizedTest?

Can someone assist me with this? Here is the content of my JSON file: { "1": "1", "2": "2", "3": "Fizz", "4": "4", "5": "Buzz", "6": ...

Is it possible to display a React Component code within a <code> tag?

I am in the process of creating a tester page that allows users to interact with a library component and document how it is being used. Here is the library component: render = () => { let component = ( <Slider onSlid ...

React's useEffect delay instability

Currently, I am in the process of creating a Pomodoro clock. My approach involves utilizing the useEffect and setTimeout functions to develop countdowns. Initially, everything appeared to be running smoothly until I noticed a delay ranging from 30ms to 50m ...

Transforming a string into JSON format for the purpose of implementing JSON Patch

I am encountering an issue while attempting to retrieve a request using postman for a JSON string in order to apply a JSON patch. Unfortunately, I am facing difficulties in converting the string to JSON once the data is posted through a variable. Each time ...

Unable to alphabetically arrange buttons automatically

I am encountering a challenge with automatically sorting buttons alphabetically on my webpage. I am unable to determine the method for sorting these buttons using jquery or javascript, but my goal is to have them sorted automatically when the page loads. I ...

I would like to modify the text color of a disabled input field

I need to adjust the font color of V1, which is a disabled input field. I want to make it darker specifically for Chrome. Any suggestions on how I can achieve this? Here's my HTML code: <mat-form-field appearance="outline" fxFlex=" ...

What is the best way to send an array of objects to a Node.js server?

What is the method for sending an array of objects with user data to the server for verification? I am attempting to pass orderform data to a server for validation and then display it on a different page after redirection. const addProductsToServer = (ev ...

Add a new item to an array in Angular 2 when a click event occurs

I'm trying to add a new list item (which comes from an API) when a button is pressed, but I'm not sure how to do it. Can anyone provide some guidance? Here's the code: <ul> <li *ngFor="let joke of jokes">{{joke.value}}</li> ...

Floating Action Button is not properly attached to its parent container

When developing my React Js app, I decided to utilize the impressive libraries of Material UI v4. One particular component I customized is a Floating Action Button (FAB). The FAB component, illustrated as the red box in the image below, needs to remain p ...