1

I have a dynamic editable table. Once the user finished the edit with the submit button i need to send JSON stringify data to python flask.

This is the javascript that on button click create the alert with the JSON object... what should i add in the same function to send this data to python flask and render an Html template?

$(function () {
$("[id*=btnFirstGenerateJson").click(function () {
    var array1 = {};
    $("[id*=tblfirstTable] .DataRow").each(function () {

        var option = $(this).find('td').eq(1).find('select').children("option:selected")

        if(option.length>0){
            value = option.text();
        } else {
            value = $(this).find('td').eq(1).text().trim();
        }

        if (value!=undefined) {

            k = $(this).find('td').eq(0).text().trim();
            value = value.replace(/\t/g, '');
            value = value.replace('\n',' ');
            array1[k]=value
        }
    });
    alert(JSON.stringify(array1));
});

});

1 Answer 1

1

Add this to your code snippet in your Javascript:

var xhr = new XMLHttpRequest();
var data = JSON.stringify(array1);
#Send the json data using the xhr variable
xhr.send(data);

Then in your flask application, you can retrieve the json files by using this code snippet inside your flask application:

@app.route('/flask_page',methods=[ "GET",'POST'])
def uploadLabel():
    #Retrieve the json file using request.files.get method of flask
    json_file = request.files.get('file')
    print(json_file)
    print(json_file.filename)
    json_file.save("./"+json_file.filename)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.