Cannot find the json via ajax
<p>I am trying to implement a simple web using flask. When I tried to read a local json data from python and pass it to the front end. It failed.</p>

<p>My file hierarchy:</p>

<pre><code>-app   
    -static
        -data
            predict.json
        scripts.js   
    -templates
        index.html  
    models.py   
    views.py   
    __init__.py 
run.py
</code></pre>

<p>Related python part:</p>

<pre><code>import os
from app import app
@app.route("/test",methods=['GET'])
def get_local_json():
    SITE_ROOT = os.path.realpath(os.path.dirname(__file__))
    json_url = os.path.join(SITE_ROOT, "static/data",'predict.json')
    data = json.load(open(json_url))
    return data
</code></pre>

<p>Related JS part in scripts.js:</p>

<pre><code>$SCRIPT_ROOT = {{ request.script_root|tojson|safe }};
$.getJSON($SCRIPT_ROOT + "/test", function (data) { ...}
</code></pre>

<p>When I run this web on my computer, the console log shows:</p>

<blockquote>
  <p>jquery-3.1.0.min.js:4 GET <a href="http://127.0.0.1:5000/predict.json" rel="nofollow">http://127.0.0.1:5000/predict.json</a> 404 (NOT
  FOUND)</p>
</blockquote>

<p>It seems not detect my modification (my first version just reads the data from JS).</p>

<p>Any hints are highly appreciated!</p>

<p>The problem here is that the browser cache the javascript file, so that no matter what modification I made, it just failed to detect it.</p>

<p>To avoid it, a smart way is to add change the js statement in html to href="xxx.js?ver=1.0"</p>

jquery python json ajax flask