Consider you should not use absolute path in your request.  Place your file
in your static folder.  Request the file relative to this static location.
This would be similar to requesting other resources, such as css and js
files...like this:

{% load staticfiles i18n %}

<link href="{% static 'css/stuff.css' %}" rel="stylesheet">

or in javascript:
const data = "{% static 'js/yourfile.js' %}";

On Mon, Jul 8, 2019 at 12:51 PM Mayank Tripathi <mayanktripath...@gmail.com>
wrote:

> Hi Team,
>
> I am making quiz app, for which i wrote a function in view which will
> generate the json file and place it under the same location as of my all
> teamplates (C:/Desktop/Environment/envQuiz/quizsetup/templates/quizsetup)
> Now I am trying to read this json file in my HTML page via javascript
> file, and getting error as attached "Issue1.PNG".
>
> Please help... I also tried using header.. but no luck.
>
> Below is the js code i am using.
> <script type="text/javascript">
> var requestURL =
> 'C:/Desktop/Environment/envQuiz/quizsetup/templates/quizsetup/json_data.json';
> let questions;
> let questionsCount;
> let currentQuestion;
> let score = 0;
>
> let question_title_elem = document.getElementById("title");
> let answers_elem = document.getElementById("answers");
> let action_btn = document.getElementById("action_btn");
>
> function getQuestions () {
> let request = new XMLHttpRequest();
> request.onreadystatechange = function () {
> if (this.readyState == 4 && this.status == 200) {
> questions = JSON.parse(this.responseText).questions;
> questionsCount = questions.length;
> currentQuestion = 0;
> }
> }
>
> /*json_data -- This is from view takeQuiz */
> request.open("GET", requestURL, false);
> request.send();
> ....
> .
> ..
> .
> .
> .
> ...
> </script>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/57fd8bf5-8056-4355-b1ec-77247445e48d%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/57fd8bf5-8056-4355-b1ec-77247445e48d%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACHQt1e0rWpZuQ5cjM9P-q4wrmZFB_zFu9Xbzx1-CmFSZyiSVg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to