Sencha Touch success callback from JSONP proxy? - sencha-touch

I am just learning sencha touch. I am trying to retrieve data form a server (following the getting started example). I am trying to print the response to the console in a success callback. Here is the code I am attempting to use, but nothing is being printed to the console.
proxy: {
type: 'jsonp',
url: 'https://ajax.googleapis.com/ajax/services/feed/load?v=1.0&q=http://feeds.feedburner.com/SenchaBlog',
reader: {
type: 'json',
rootProperty: 'responseData.feed.entries'
},
listeners: {
success: function(response) {
console.log(response)
}
}
so, what is the proper syntax for a success callback so that I can do some stuff with the response like print it in the console?
Thanks!

Change this
rootProperty: 'responseData.feed.entries'
for this:
root: 'responseData.feed.entries'
Or could you change proxy: {type: 'jsonp' ... } for proxy: {type: 'ajax' ... } plus above.
I hope these helps.

Related

FB.ui response callback not working on mobile device

I have a function that triggers a Facebook share dialogue. When the user has successfully shared a site, the callback function calls a AJAX post that updates a counter in my database (rails). This works fine on desktop but when I test this on a mobile device (Safari), the callback function is not triggered at all:
function shareOnFacebook(){
FB.init({
appId : 'xxxxxx',
xfbml : true,
version : 'v2.5'
});
FB.ui({
method: 'share',
name: 'foo',
picture: 'http://mypic.com',
href: 'http://mypage.com',
description: 'descr'
}, function(response) {
if(response){
$.ajax({
url: "/my-app/post-url",
type: 'POST',
data: {
some_id: 123
}
});
}
else{}
});
}
I digged through the docu but could not find any response on what I am doing wrong. Maybe you guys have a hint. Appreciated.

i can load the model using direct but not from other server

**I am getting result for the below coding**
Ext.define('User', {
extend: 'Ext.data.Model',
fields: ['id', 'name', 'age'],
proxy: {
type: 'rest',
url : 'http://localhost:8085/sencha-touch-2.0.1.1-gpl/sencha-touch-2.0.1.1/docs/guides/data/examples/model_with_proxy/data/users/',
reader: {
type: 'json',
root: 'users'
}
}
});
**But when i try to get from other server i can't.I have tried this coding given below**
Ext.define('User', {
extend: 'Ext.data.Model',
fields: ['id', 'name', 'age'],
proxy: {
type: 'jsonp',
url : 'http://docs.sencha.com/touch/2-1/guides/data/examples/model_with_proxy/data/users/',
reader: {
type: 'json',
root: 'users'
}
}
});
var userStore;
Ext.require('Ext.data.Store');
Ext.onReady(function() {
// Uses the User Model's Proxy
userStore = Ext.create('Ext.data.Store', {
model: 'User',
autoLoad: true
});
// Gives us a reference to the User class
var User = Ext.ModelMgr.getModel('User');
var ed = Ext.create('User', {
name: 'Ed Spencer',
age : 25
});
// We can save Ed directly without having to add him to a Store first because we
// configured a RestProxy this will automatically send a POST request to the url data/users
ed.save({
success: function(ed) {
console.log("Saved Ed! His ID is "+ ed.getId());
}
});
// Load User 1 and do something with it (performs a GET request to /users/1)
User.load(1, {
success: function(user) {
console.log("Loaded user 1: " + user.get('name'));
}
});
});
I am getting the error
Uncaught TypeError: Object [object Object] has no method 'writeRecords' ext-all.js:18
Resource interpreted as Script but transferred with MIME type text/html: "http://docs.sencha.com/touch/2-1/guides/data/examples/model_with_proxy/data/users/?_dc=1352957198178&page=1&start=0&limit=25&callback=Ext.data.JsonP.callback1". ext-all.js:18
Uncaught SyntaxError: Unexpected token :
If anyone knows can share with me

passing parameters to RIA service from extjs with json end point

I am trying to communicate with RIA service from extjs using POST for getting response with following code.
var store = Ext.create('Ext.data.Store', {
model: 'RootResults',
proxy: {
type: 'ajax',
actionMethods: 'POST',
url: 'MyService.svc/JSON/GetRes',
headers: {
'Content-type': 'application/json'
},
reader: {
type: 'json',
root: 'GetResResult.RootResults',
totalProperty: 'GetResResult.TotalCount'
}
, pageParam: undefined,
startParam: undefined,
limitParam: undefined
, success: function (response) {
alert(response);
}
}
});
var operation = new Ext.data.Operation({
FId: 1,
SId: 0
});
store.load({ params: Ext.encode(operation) });
i can access it with get.
when i am trying with POST, it returning error - "405 Method Not Allowed".
what to do to make it POST enabled?
When i asked this question, i am bit confused with POST communication between extjs and RIA services.
I solved this with the help of following article
http://www.joseph-connolly.com/blog/post/WCF-RIA-Services-jQuery-and-JSON-endpoint-Part-2.aspx
For accessing WCF RIA Services from jquery or extjs, actually we need to create changeset for CUD(Create-Update-Delete) operations and All of the operations use JSON/SubmitChanges.
I believe that on the server end you need to add HasSideEffects to your method declaration ():
[Invoke(HasSideEffects = true)]
public GetPages(...)
{
}

extjs4 store addes get params in the url

i'm using extjs4 store
In xhtpp calls it shows the http://localhost/home_dir/index.php/questions/content_pie?_dc=1312366604831&hi=&page=1&start=0&limit=25
This is the store code
var content_type_store = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
url: BASE_URL+'questions/content_pie',
method:'POST',
params :{hi:''}
}),
reader: new Ext.data.JsonReader({
root: 'results'
}, [
'qtype',
'qval'
])
});
Even though i set the method as POST its get params appears in url
I'm using codeigniter as my framework. I disabled GET params in CI. Iwnat to send params in post. with ext2 and 3 this code worked fine..
Help me
Thanks
method:'POST' in proxy's config won't work. There is no such config option. However there are two ways to make store use POST. The simplier one - just override getMethod function:
var content_type_store = new Ext.data.Store({
proxy: {
type: 'ajax',
url: BASE_URL+'questions/content_pie',
extraParams :{hi:''},
// Here Magic comes
getMethod: function(request){ return 'POST'; }
},
reader: {
type: 'json',
root: 'results'
}
});
The second way: override proxy's actionMethods property. If you choose this way your proxy should look like this:
// ...
proxy: {
type: 'ajax',
url: BASE_URL+'questions/content_pie',
extraParams :{hi:''},
// Here Magic comes
actionMethods: {
create : 'POST',
read : 'POST',
update : 'POST',
destroy: 'POST'
}
},
// ...

Consuming an OData request in Sencha Touch with JSONP

I'm working on a Sencha Touch app and I want to use OData so I have been playing around with the netflix Odata service. When I send my request with JSONP in Sencha I can see the request come back when I trace it, however my callback function is never getting called. Can anyone help? Here is my code.
var blah = function () {
Ext.util.JSONP.request({
url: 'http://odata.netflix.com/catalog/Titles()',
callbackKey: 'callback',
params: {
$format: 'json',
$top: '10',
$filter: "startswith(Name,'C')",
$select: "ShortName"
},
callback: function (result) {
alert('asdf');
var data = result;
if (data) {
alert('data');
} else {
alert('There was an error during retrieving data.');
}
}
});
}
var button = new Ext.Button({
text: 'Ajax',
listeners: {
'tap': blah
}
});
Thanks in advance
If you're getting a syntax error on the server response quotes, this is a known issue described here for which there is an available update.
The server is returning XML, not JSON data.