A
A
Alexander2015-03-14 13:27:15
JavaScript
Alexander, 2015-03-14 13:27:15

How to process ajax request?

Good afternoon, I understand ajax and flask, here I have such a function

@app.route('/ajax', methods=['GET', 'POST'])
def ajax_output():
    if request.method == 'POST':
        usd = usd_value()
        euro = euro_value()
        return jsonify(result=[usd, euro])
    return render_template('Login.html')

this function transmits dollar rates,
tell me how to make an ajax request that will contact the server every 10 seconds, and request dollar rates, I've been fighting with this for 3 days, I don't understand what's what)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Inik1I, 2015-03-14
@AlexMine

Here is an example:

<script src="http://code.jquery.com/jquery-1.5.min.js"></script>
<script>
function check(){
  $.post("/ajax", {}, function(data){$("input[name='currency']").val(data)});
}
setInterval(check, 10000);
</script>
<input type="text" name="currency" readonly>

I hope getting data from json and displaying it where you need it will not be difficult.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question