简体   繁体   中英

Responding to jQuery Ajax request with Python

I am currently trying to implement the pre-built inline editor located here: https://github.com/wbotelhos/inplace

Unfortunately, the support documentation leaves a lot to desire and I have very little experience with Javascript, jQuery, or Ajax.

I have been able to successfully implement the HTML edits:

<td><div class="inplace" data-field-name="name" data-field-value="{{people['name']}}" data-url="/update/{{id}}">{{ people['name'] }}</a></td>

The Js:

<script type="text/javascript">
$('.inplace').inplace();
</script>

and have successfully grabbed, and printed the info sent from the Javascript.

@app.route('/update/<id>', methods=["POST", "PATCH"])
@login_required
def update(id):
    new_data = request.get_data(as_text=True)
    print(new_data)
    return "200"

The issue I am facing, is that the Js returns an Undefined value which is what the HTML updates to.

Ignore the return "200" - I have tired several different methods. Success = True, json values, etc and nothing seems to work.

I am sure I am missing something simple.

It looks like you need to print json with the field name that matches your field_name attribute which is name.

So you will need to print something like this. I don't use python, so you will need to follow actual python syntax. Where the word name is correct, but you will need to add the value that you want shown

print('{"name":"NEW FIELD VALUE"}')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM