| From | Sent On | Attachments |
|---|---|---|
| Johannes Fahrenkrug | Nov 18, 2010 5:24 am | |
| Ido Ran | Nov 18, 2010 10:49 pm | |
| Johannes Fahrenkrug | Nov 22, 2010 12:14 am | |
| Johannes Fahrenkrug | Nov 22, 2010 2:03 am |
| Subject: | [sproutcore] Re: JSONP? | |
|---|---|---|
| From: | Johannes Fahrenkrug (jfah...@gmail.com) | |
| Date: | Nov 22, 2010 2:03:32 am | |
| List: | com.googlegroups.sproutcore | |
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
On Nov 22, 9:15 am, Johannes Fahrenkrug <jfah...@gmail.com> wrote:
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('http://ajax.googleapis.com/ajax/services/search/ images?v=1.0&rsz=large&imgtype=photo&q='+query.query+'&callback=?', null, function(data, textStatus, xhr) { SC.run(function() { 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); },
Cheers,
Johannes
On Nov 19, 7:49 am, Ido Ran <ido....@gmail.com> 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 SC.run and process you result inside if you want binding and everything else to work correctly.
Ido
On Nov 18, 3:24 pm, Johannes Fahrenkrug <jfah...@gmail.com> wrote:
Hi,
I want to load data
fromhttp://ajax.googleapis.com/ajax/services/search/images.json?v=1.0&rsz...
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,
Johannes
--
You received this message because you are subscribed to the Google Groups
"SproutCore" group.
To post to this group, send email to spro...@googlegroups.com.
To unsubscribe from this group, send email to
sproutcore+unsu...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/sproutcore?hl=en.





