Home » Javascript » How to pass javascript variable in jinja variable while using Ajax

How to pass javascript variable in jinja variable while using Ajax

Posted by: admin June 30, 2018 Leave a comment

Questions:

Hi I’m using Ajax to pass data from client to server. I intend to call a Python function with a javascript variable as the argument. I’m using the ‘url_for’ method in Jinja and it’s not working. I’m doing this:

{data: "somedata",
    render: function ( data, type, row, meta ) {
  return '<a href={{url_for("foo.bar", arg='+data+')}}>'+data+'</a>';
}},

Here ‘arg’ is the argument of the Python function and instead of passing the js variable ‘data’, it passes the whole thing as a string, like this: ‘+data+’

What am I doing wrong here? Is this method even possible? What can be the alternative to this. How can I call the python function with js variable ‘data’ as the argument. I’m new to this, any help would be appreciated.

Answers: