jquery

Flask, how to return a success status code for ajax call

Flask, how to return a success status code for ajax call Question: On the server-side, I am just printing out the json-as-dictionary to the console @app.route(‘/’,methods=[‘GET’,’POST’]) @login_required def index(): if request.method == “POST”: print request.json.keys() return “hello world” Now, whenever I make a post request via ajax, the console prints out the dictionary with the …

Total answers: 6

Adding a jQuery script to the Django admin interface

Adding a jQuery script to the Django admin interface Question: I’m gonna slightly simplify the situation. Let’s say I’ve got a model called Lab. from django.db import models class Lab(models.Model): acronym = models.CharField(max_length=20) query = models.TextField() The field query is nearly always the same as the field acronym. Thus, I’d like the query field to …

Total answers: 1

how can I use data posted from ajax in flask?

how can I use data posted from ajax in flask? Question: I’m having trouble getting data POSTed from jquery ajax. $(‘#clickme’).click( function() { var data = save_input(); // data data[‘_sid’] = $survey_id; // survey_id injected from flask data[‘_uip’] = $user_ip; // user_ip injected from flask, request.remote_addr $.ajax({ type : “POST”, url : “{{ url_for(‘mod.load_ajax’) }}”, …

Total answers: 5

Minimalistic example of IPython kernel javascript bi-directional communication

Minimalistic example of IPython kernel javascript bi-directional communication Question: My goal is to write an interactive variable viewer for IPython, i.e. which allows one to see, say nested dicts/lists as a tree, and drill down (a bit like the console.log in Javascript). I spent a lot of time trying to extract minimalistic code out of …

Total answers: 1

Jquery ajax post request not working

Jquery ajax post request not working Question: I have a simple form submission with ajax, but it keeps giving me an error. All the error says is “error”. No code, no description. No nothing, when I alert it when it fails. Javascript with jQuery: $(document).ready(function(){ $(“.post-input”).submit(function(){ var postcontent = $(“.post-form”).val(); if (postcontent == “”){ return …

Total answers: 3

In Javascript a dictionary comprehension, or an Object `map`

In Javascript a dictionary comprehension, or an Object `map` Question: I need to generate a couple of objects from lists in Javascript. In Python, I’d write this: {key_maker(x): val_maker(x) for x in a_list} Another way to ask is does there exist something like jQuery.map() which aggregates objects? Here’s my guess (doesn’t work): var result = …

Total answers: 7

Jquery and Django CSRF Token

Jquery and Django CSRF Token Question: I have 2 html Pages. A Parent Page and a Child Page. The Child Page Contains a Submit Button that runs code on the Parent Page to submit an Ajax message. I load the child page using $.load() method and then when the button is clicked it runs a …

Total answers: 3

Make Javascript do List Comprehension

Make Javascript do List Comprehension Question: What is the cleanest way to make Javascript do something like Python’s list comprehension? In Python if I have a list of objects whose name’s I want to ‘pull out’ I would do this… list_of_names = [x.name for x in list_of_objects] In javascript I don’t really see a more …

Total answers: 11

jquery-like HTML parsing in Python?

jquery-like HTML parsing in Python? Question: Is there any way in Python that would allow me to parse an HTML document similar to what jQuery does? i.e. I’d like to be able to use CSS selectors syntax to grab an arbitrary set of nodes from the document, read their content/attributes, etc. Asked By: Roy Tang …

Total answers: 4