79392320

Date: 2025-01-27 22:30:00
Score: 0.5
Natty:
Report link

Thanks to efeakaroz13's hint I adjusted my code to the following working solution.

Javascript:

function updateSourceState(sourceTypeId, sourceId, dataForUpdate) {
    $.ajax({
            url: '/update',
            data: {source_type_id: sourceTypeId, source_id: sourceId, data_for_update: JSON.stringify(dataForUpdate)},
            method: 'PUT',
            success: function (data) {
                console.log('Data updated successfully');
            },
            error: function(data) {
                console.log('Data update failed. Response: ' + data);
            }
        }).done(function() {
            console.log('DONE: data updated successfully');
        }).fail(function(msg) {
            console.log('FAIL: data update failed: ' + msg);
        }).always(function(msg) {
            console.log('ALWAYS message: ' + dataForUpdate + ', url: ' + url);
        });
}

Python/Flask "PUT" route:

@bp.route('/update', methods=["GET", "PUT"])
def update_source_state():
    source_id = request.form.get('source_id')
    source_type = request.form.get('source_type_id')
    dataForUpdate = request.form.get('data_for_update')

    # build endpoint url (could be done in route annotation too...)
    url = '{0}/{1}/source/{2}'.format(ARCHIVE_CONFIG_BASE_URL, source_type, source_id)

    response = requests.put( url=url
                            , data=dataForUpdate
                            , headers={'Content-Type': 'application/json', 'accept': 'application/json'}
                            )

        ...

Note that dataForUpdate is a JSON object. The code did not work before I stringified it.

Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Blacklisted phrase (1): did not work
  • Long answer (-1):
  • Has code block (-0.5):
  • Self-answer (0.5):
Posted by: WolfiG