jQuery AJAX cross domain

Use JSONP. jQuery: PHP: The echo might be wrong, it’s been a while since I’ve used php. In any case you need to output callbackName(‘jsonString’) notice the quotes. jQuery will pass it’s own callback name, so you need to get that from the GET params. And as Stefan Kendall posted, $.getJSON() is a shorthand method, but then you need to …

Read more

How to overcome “datetime.datetime not JSON serializable”?

Updated for 2018 The original answer accommodated the way MongoDB “date” fields were represented as: {“$date”: 1506816000000} If you want a generic Python solution for serializing datetime to json, check out @jjmontes’ answer for a quick solution which requires no dependencies. As you are using mongoengine (per comments) and pymongo is a dependency, pymongo has built-in utilities to help …

Read more

Return JSON response from Flask view

As of Flask 1.1.0 a view can directly return a Python dict and Flask will call jsonify automatically. If your Flask version is less than 1.1.0 or to return a different JSON-serializable object, import and use jsonify.

How to compare arrays in JavaScript?

To compare arrays, loop through them and compare every value: Comparing arrays: Usage: You may say “But it is much faster to compare strings – no loops…” well, then you should note there ARE loops. First recursive loop that converts Array to string and second, that compares two strings. So this method is faster than use …

Read more

Converting JSON data to Java object

I looked at Google’s Gson as a potential JSON plugin. Can anyone offer some form of guidance as to how I can generate Java from this JSON string? Google Gson supports generics and nested beans. The [] in JSON represents an array and should map to a Java collection such as List or just a plain Java array. The {} in JSON …

Read more