How to parse link header from github API

The parse-link-header NPM module exists for this purpose; its source can be found on github under a MIT license (free for commercial use). Installation is as simple as: npm install parse-link-header Usage looks like the following: var parse = require(‘parse-link-header’); var parsed = parse(‘<https://api.github.com/repos?page=3&per_page=100>; rel=”next”, <https://api.github.com/repos?page=50&per_page=100>; rel=”last”‘) …after which one has parsed.next, parsed.last, etc: { … Read more

JSONP call showing “Uncaught SyntaxError: Unexpected token : “

Working fiddle: http://jsfiddle.net/repjt/ $.ajax({ url: ‘https://api.flightstats.com/flex/schedules/rest/v1/jsonp/flight/AA/100/departing/2013/10/4?appId=19d57e69&appKey=e0ea60854c1205af43fd7b1203005d59’, dataType: ‘JSONP’, jsonpCallback: ‘callback’, type: ‘GET’, success: function (data) { console.log(data); } }); I had to manually set the callback to callback, since that’s all the remote service seems to support. I also changed the url to specify that I wanted jsonp. You’re trying to access a JSON, not … Read more

Simple jQuery, PHP and JSONP example?

When you use $.getJSON on an external domain it automatically actions a JSONP request, for example my tweet slider here If you look at the source code you can see that I am calling the Twitter API using .getJSON. So your example would be: THIS IS TESTED AND WORKS (You can go to http://smallcoders.com/javascriptdevenvironment.html to … Read more

How to solve JSON_ERROR_UTF8 error in php json_decode?

There is a good function to sanitize your arrays. I suggest you use a json_encode wrapper like this : function safe_json_encode($value, $options = 0, $depth = 512, $utfErrorFlag = false) { $encoded = json_encode($value, $options, $depth); switch (json_last_error()) { case JSON_ERROR_NONE: return $encoded; case JSON_ERROR_DEPTH: return ‘Maximum stack depth exceeded’; // or trigger_error() or throw … Read more

parsererror after jQuery.ajax request with jsonp content type

JSONP requires that the response be wrapped in some kind of callback function, because it works by injecting a script tag into the document as a mechanism to load data from another domain. Essentially, what happens is a script tag gets dynamically inserted into the document like so: <script src=”http://the.other.server.com/foo?callback=someFn”></script> callback is dependent on the … Read more

AJAX cross domain call

The only (easy) way to get cross-domain data using AJAX is to use a server side language as the proxy as Andy E noted. Here’s a small sample how to implement that using jQuery: The jQuery part: $.ajax({ url: ‘proxy.php’, type: ‘POST’, data: { address: ‘http://www.google.com’ }, success: function(response) { // response now contains full … Read more

Is JSONP safe to use?

Update: JSONP is a common hack to do cross-domain requests. Modern browsers now have Cross Origin Resource Sharing, and IE8+ have XDomainRequest which is similar. See http://enable-cors.org/ for more info. JSONP is just a script include that allows you to use a callback. You should however be aware of Cross-site request forgery (CSRF). As long … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)