Home > OS >  Responding to jQuery Ajax request with Python
Responding to jQuery Ajax request with Python

Time:07-15

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  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.

CodePudding user response:

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"}')
  • Related