flask jquery : how to show return jsonify (json) to same html template without refresh

问题内容:

view.py

@bp.route('/')
def index():
    return render_template('index.html')

@bp.route('/news')
def news(id):
    return jsonity({'news':'newsnewsnews'})

index.html

<section>
<span id='show_news'> 
    <!--show news here--> 
  </span>
</section>
<section>
<a id ='kick' href="{{ url_for('bp.news', _anchor='show_news') }}">
Click to see news
</a>
</section>

setnews.js

$(document).ready(function() {

 $("#kick").click(function() {

    $.getJSON({
    url: "/news",
    success: function(data){
        $("#show_news").text(JSON.stringify(data));

    }
    });

 });

});

i dont want to refresh the page cuz index page have two section and first section slide out from the right.
i jst want to show json text in first <section> <span> ….
hlp me please,thanks.

问题评论:

1  
And what’s not working? Please see Minimal, Complete, and Verifiable example.
    
not displaying json values in the first <span>
– Sumit Rawat
56 mins ago
    
I can’t reproduce your issue. Please edit to include a Minimal, Complete, and Verifiable example.

原文地址:

https://stackoverflow.com/questions/47752953/flask-jquery-how-to-show-return-jsonify-json-to-same-html-template-without-r

添加评论

友情链接:蝴蝶教程