Ways to retrieve the information sent from the views via ajax

template.html

success: function (result, data) {
  alert(result["val"]);
  check = result[0]
  alert(check);
  var chart = new Highcharts.Chart({
    chart: {
      renderTo: 'container',
      type: 'line',
      marginRight: 200,
      marginBottom: 75,
      marginLeft: 70,
      marginTop: 80,
      width: 900
    },
    title: {
      marginTop: 100,
      text: result[4]
    },
    xAxis: {
      categories: result[1]
    },
  {%if result.0 == "power" %}
    yAxis: {
      min: 0,
      max: 30
    },
  } 
  {%else %}
    yAxis: {
      min: 0.85,
      max: 1
    }, 
  {% endif %}

views.py

     list_values.append("power")
     list_values.append(m)
     list_values.append(p)
     list_values.append(q)
     list_values.append(msg)

     print list_values
     response.content = json.dumps(list_values, cls=DjangoJSONEncoder)
     return response

i am trying to plot the y axis based on the value i am sending from views. but it always goes to the else part. i am making a ajax request. How do i access the data i am passing from views in template where im using ajax.

Answer №1

It appears that there may be a mix of Javascript, Django views, and Django templates going on.

In the success callback function of your javascript code, make sure to only use objects from the json response. (To simplify things)

success : function(result, data) {
    // Displaying objects
    console.log(result);
    console.log(data);
}

If your JSON response is correct, the Javascript functionality has no direct relationship with Django.

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

Create a regular expression in Javascript that only matches strings that do not contain any periods

Struggling with setting up an express route for localhost:3000/test and utilizing regex to handle specific URL patterns. Need assistance combining regex with Express params functionality. router.get('/test/:path[\s^.]*$', function () { ...

What is the process by which Single Page Applications manage the Not Modified 304 response?

Imagine a scenario where a Single Page Application (SPA) built using angular or vuejs loads 3 components on a page, with each component making requests to different backend APIs. Now, if a user decides to refresh the page, those same 3 API calls are trigg ...

Revamped link and XMLHttpRequest

Is it possible to successfully integrate ajax with rewritten urls? For example, I have a php file called "ajaxfile.php" that receives a post method call from JavaScript and has been rewritten to "/rewritten-url/". Here is the JavaScript code: $(document) ...

JqueryUI Autocomplete functions flawlessly on JSFiddle but fails to work on the actual website

After spending hours working on it, I still can't seem to figure it out. The code functions perfectly on JSFiddle, but not on my own website. Here is the link to the JSFiddle: http://jsfiddle.net/x69chen/sbAR6/16/ I've also included the links ...

Error message "Function pointer is not a valid function" encountered in Angular version 1.2.25

I am encountering this error sporadically and without any specific pattern. Previously, the page was functioning correctly, but now this error is causing disruptions. Is there a recommended method for debugging or tracing the source of this problem? Err ...

The use of .eq() returns an error message stating "not a valid function."

When attempting to extract information from an ajax object, I encountered an issue with the jQuery function within a .then() method. The error message "data.items.eq is not a function" appears on the screen. Despite my efforts with a combination of .eq() a ...

Altering the color of numerous labels using ajax jQuery and .NET Core MVC

I have developed a feature that allows users to choose answers using radio buttons. Once the user has selected all answers and clicked Submit, the answer labels will be displayed in the following three scenarios: If the user selects the correct answer lab ...

The submit button seems to be unresponsive or unreactive

As a newcomer to Angular 2 and Typescript, I am in the process of building a web application. I have created several input fields and, following user submission via a button, I want to log the inputs to the console. However, it seems like my button is not ...

Bring in styles from the API within Angular

My goal is to retrieve styles from an API and dynamically render components based on those styles. import { Component } from '@angular/core'; import { StyleService } from "./style.service"; import { Style } from "./models/style"; @Component({ ...

Purging browser cache with the help of jQuery or AngularJS

I am currently working on clearing the browser cache through programming. This is necessary because I have updated the application to a new version, but the browser continues to display the old version and content stored in the cache. I want to ensure that ...

What is the best way to set an object's value to null in AngularJS?

Check out this code snippet var data={}; data={stdId:"101"}; data={empId:"102"}; data={deptId:"201"}; In my project, I'm receiving data from services into a data object with differing key names such as stdId or empId, etc. I need to set empty val ...

Are your GetJSON requests failing to execute properly?

I have a code snippet that executes in a certain sequence and performs as expected. <script> $.getJSON(url1, function (data1) { $.getJSON(url2, function (data2) { $.getJSON(url3, function (data3) { //manipulate data1, data2, ...

Verify the attribute of the child element

In my child component, I have a property named files, which is an input type=file. This property allows me to determine if the user has selected a file for upload so that I can disable the submit button if no files are present in the input field. The issue ...

Field must have a base type specified to proceed

Currently, I am in the process of developing a discord.js bot. The structure I have set up involves a folder that contains all the commands, and when a command is called, index.js directs it to the appropriate file. However, when attempting to run the bot, ...

Particles.js fails to persist as I scroll down the HTML page

After creating a website page, I incorporated Particles.js for the background. However, when I scroll down, the particles seem to be confined to the initial corner of the screen and do not continue downward. Here are my current particle settings: #particl ...

What is the solution for correcting the caret position in the Notification box?

I've encountered an issue with my Bootstrap dropdown notification system. I've noticed that the caret, which is intended to be positioned below the message icon, often moves away from it when viewed on different devices or screen sizes. Is there ...

URL JSON data will not display markers

I am currently working on a map that fetches data from the police.uk API by allowing users to drag and drop a dot on the map to display crimes within a 1-mile radius. However, I'm facing an issue when trying to implement geocoding functionality by tak ...

What is the best way to execute ajax functions one after another?

Is there a way to execute ajax functions sequentially without using asynch: false? Using asynch: false can cause the browser to hang, so I'm looking for an alternative method. I have 5 checkboxes, named ch1, ch2, ch3, ch4, ch5, each with a value corre ...

Concealing the file input using CSS and JavaScript

One way to hide the file input is by using this code snippet. <div class="custom_btn" >Click to upload</div> <input type="file" name="photo" id="hidden_btn" style="display:none;" /> Next, JavaScript can be used to trigger the hidden inp ...

Enabling real-time notifications through Express 4 middleware with socket.io integration

I am in the process of developing a real-time notification system utilizing socket.io. Here is the current server-side code I have implemented: bin/www: var app = require('../app'); var server = http.createServer(app); var io = app.io io.attac ...