Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need to access the request object on the server side to get the arguments. I'm assuming you're using Flask, but if not, the basic idea should be the same on other web frameworks as well. Let's say you have a simple little index.html, where you use Javascript to make your Ajax query:</p> <pre><code>$.get("{{ url_for('ajax') }}", {name: "John", time: "2pm"}); </code></pre> <p>Note that if you're not using Jinja2 to render the script portion, replace the url_for()-call with the actual URL, so something like /ajax in my example further below: </p> <pre><code>$.get("/ajax", {name: "John", time: "2pm"}); </code></pre> <p>Now, on the server side you would have something like this:</p> <pre><code>from flask import Flask, render_template, request app = Flask(__name__) @app.route('/ajax') def ajax(): #Access arguments via request.args name = request.args.get('name') time = request.args.get('time') #NOTE: In real code, check that the arguments exist #Silly logging call to show that arguments are there app.logger.info(name) app.logger.info(time) #Do stuff here to do what you want or modify name/time ... #Render template and pass the arguments to it return render_template('ajax.html', name=name, time=time) @app.route('/index') def index(): return render_template('index.html') if __name__ == '__main__': app.run(debug=True) </code></pre> <p>and ajax.html would look something like this for example:</p> <pre><code>&lt;h2&gt;{{ name }}&lt;/h2&gt; &lt;h2&gt;{{ time }}&lt;/h2&gt; </code></pre> <p>So request.args is where you can access the arguments you've passed with GET, but you need to pass them explicitly to Jinja2 with the render_template() call. Jinja2 is just a templating language and it is not aware of your arguments (1) unless you pass them to it.</p> <p>1) With some exceptions. Flask for example does pass a few arguments to Jinja2 implicitly, like the request object.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload