atom feed4 messages in com.googlegroups.sproutcore[sproutcore] Re: JSONP?
FromSent OnAttachments
Johannes FahrenkrugNov 18, 2010 5:24 am 
Ido RanNov 18, 2010 10:49 pm 
Johannes FahrenkrugNov 22, 2010 12:15 am 
Johannes FahrenkrugNov 22, 2010 2:03 am 
Subject:[sproutcore] Re: JSONP?
From:Johannes Fahrenkrug (
Date:Nov 22, 2010 2:03:55 am

Correction: after running sc-build, Q$ is not available anymore. So you do need to put jquery-min.js into your application folder, run sc- build and just use $.getJSON instead of Q$.getJSON.

- Johannes

Thanks for the tip, Ido!

For anyone who is interested: This is how I solved it. I didn't need to add jquery explicitly since it already comes with SproutCore and is available through the Q$ global var.

In production, I use jquery for the request, supply an anonymous callback function that creates a SC.Response object and then calls the normal didFetchImages callback method:

fetch: function(store, query, params) {     var self = this;     console.log('in fetch');     if (SC.buildMode === 'debug') {       SC.Request.getUrl('ajax/services/search/images? v=1.0&rsz=large&imgtype=photo&q='+query.query).json()         .notify(this, 'didFetchImages', store, query)         .send();     } else  {       // in production we need to use jsonp with jquery to work around cross domain restrictions       Q$.getJSON(' images?v=1.0&rsz=large&imgtype=photo&q='+query.query+'&callback=?', null,         function(data, textStatus, xhr) {  {             var response = SC.Response.create({ request: null, body: data, status: textStatus });             self.didFetchImages(response, store, query);           });         });     }

    return YES;   },

  didFetchImages: function(response, store, query) {     console.log('in didfetch');     var data;     if (SC.ok(response)) {       console.log('response ok');       data = response.get('body').responseData.results;

      var storeKeys = store.loadRecords(ImageSearch.GoogleImage, data);       store.loadQueryResults(query, storeKeys);

      store.dataSourceDidFetchQuery(query);     }     else store.dataSourceDidErrorQuery(query, response);   },


On Nov 19, 7:49 am, Ido Ran <> wrote:

Hi, I did this by adding jquery.js file into my application and simply use $.getJSON - if you all callback? to the url you pass to getJSON it will use JSONP to get it. Just remember one thing: inside you callback method you should call and process you result inside if you want binding and everything else to work correctly.


On Nov 18, 3:24 pm, Johannes Fahrenkrug <> wrote:


I want to load data
from in my SproutCore app. But due to the same origin policy that's not possible in production (no problem in development mode with sc-server and proxy). Is there any way to do this in SproutCore? Do I have to include jQuery and do it with jQuery? Is there any native JSONP support in SproutCore?

Plus, the .header()  that I set on an SC.Request doesn't seem to be honored.

Thanks and cheers,