Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The issue is with to do with how sammy.js determines the type of data it's retrieving. When you load "mydata.json" the .json tells sammy.js that this is JSON data, however when loading "'http://samedomain/api/getdata'" it assumes it's just plain text data.</p> <p>I don't know what the best approach would be but two possible solutions are either to change your routing or convert the loaded items to JSON using this.json(...) like so:</p> <pre><code>this.get('#/contact', function(context) { this.load('http://samedomain/api/getdata') .then(function(items) { $.each(this.json(items), function(i, item) { context.log(item); }); }); }); </code></pre> <p>Make sure your app has loaded the JSON library with this.use(Sammy.JSON) and that the JSON plugin is loaded in your script definitions.</p> <p><strong>Edit:</strong> Another option is you can write a custom function that knows to load JSON, here is an example plugin that you could use:</p> <p>Sammy.JSON.LoadJSON.js:</p> <pre><code>(function($) { Sammy.JSON.LoadJSON = function(app) { app.helpers({ loadJSON: function(location, options, callback) { options = $.extend(options, {json: true}); return new Sammy.RenderContext(this).load(location, options, callback); } }); } })(jQuery); </code></pre> <p>app.js:</p> <pre><code>this.use(Sammy.JSON.LoadJSON); var app = $.sammy('#mytag', function() { this.get('#/contact', function(context) { this.loadJSON('http://samedomain/api/getdata') .then(function(items) { $.each(items, function(i, item) { context.log(item); }); }); }); }); </code></pre>
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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