Python Flask sortable list result from jquery -
i manage point edit route gets invoked, cant figure out, how receive data site, im pretty confused if have use ajax or json too...
html:
{% extends "layout.html" %} {% block body %} <script src="//code.jquery.com/jquery-1.10.2.js"></script> <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script> <script> $(function() { $( "#sortable" ).sortable({ axis: 'y', update: function (event, ui) { var data = $(this).sortable('serialize'); // post server using $.post or $.ajax $.ajax({ result: data, type: 'post', url: '/edit/' }); } }); $( "#sortable" ).disableselection(); }); </script> <ul id="sortable"> {% elem in tables_list %} <li id={{ elem['id'] }}> {{elem['table_name']}} ({{ elem['norm_cap'] }} / {{ elem['max_cap'] }})</li> {% endfor %} </ul> {% endblock %}
flask:
@app.route("/edit/", methods=['get', 'post']) def edit(): if request.method == "post": priority_list = request.args.get('result', []) return "thank you"
once i'll data, know mysql, need able script posts. thank in advance
you can use getlist (similar django's getlist) data ajax.
since using jquery send request, sure flag ajax request traditional either setting jquery.ajaxsettings.traditional = true;
or altering current code to...
// post server using $.post or $.ajax $.ajax({ result: data, traditional: true, type: 'post', url: '/edit/' });
inside flask application alter existing code read
@app.route("/edit/", methods=['get', 'post']) def edit(): if request.method == "post": priority_list = request.values.getlist('results') return "thank you"
Comments
Post a Comment