Bad JSON – Keys are not quoted

You have an HJSON document, at which point you can use the hjson project to parse it: >>> import hjson >>> hjson.loads(‘{javascript_style:”Look ma, no quotes!”}’) OrderedDict([(‘javascript_style’, ‘Look ma, no quotes!’)]) HJSON is JSON without the requirement to quote object names and even for certain string values, with added comment support and multi-line strings, and with … Read more

Using JSONP to get JSON data from another server

You can use many ways but the two most convenient ones are either an AJAX call or to use jQuery’s getJSON() method Using AJAX call $(document).ready(function() { $(“.btn”).click(function() { $.ajax({type: “get”, url: “http://api.forismatic.com/api/1.0/”, data: {method: “getQuote”,format: “jsonp”,lang: “en”}, dataType: “jsonp”, jsonp: “jsonp”, jsonpCallback: “myJsonMethod” }); }); }); function myJsonMethod(response){ console.log (response); } In the above … Read more

Sending JSONP vs. JSON data?

JSONP is simply a hack to allow web apps to retrieve data across domains. It could be said that it violates the Same Origin Policy (SOP). The way it works is by using Javascript to insert a “script” element into your page. Therefore, you need a callback function. If you didn’t have one, your Javascript … Read more

jQuery JSONP ajax, authentication header not being set

I had the same problem recently. Try this: $.ajax({ url: “https://www-opensocial.googleusercontent.com/api/people/@me/@all”, dataType: ‘jsonp’, data: { alt: ‘json-in-script’ }, success: function(data, status) { return console.log(“The returned data”, data); }, beforeSend: function(xhr, settings) { xhr.setRequestHeader(‘Authorization’,’Bearer ‘ + token); } }); EDIT: Looks like it can’t be done with JSONP. Modify HTTP Headers for a JSONP request

Pushing data to Google spreadsheet through JavaScript running in browser

Step-by-step instructions with screenshots After reading Martin Hawskey‘s good introduction (to sending data from an HTML form to a Google Spreadsheet) and seeing a few gaps/assumptions, we decided to write a detailed/comprehensive tutorial with step-by-step instructions which a few people have found useful: https://github.com/dwyl/html-form-send-email-via-google-script-without-server The script saves any data sent via HTTP POST in the … Read more

Confused on how a JSONP request works

The callback is a function YOU’VE defined in your own code. The jsonp server will wrap its response with a function call named the same as your specified callback function. What happens it this: 1) Your code creates the JSONP request, which results in a new <script> block that looks like this: <script src=”http://server2.example.com/RetrieveUser?UserId=1234&jsonp=parseResponse”></script> 2) … Read more