PDA

View Full Version : JSON Request with Wordpress JSON API



Vinzcent
14 Feb 2011, 2:04 AM
Hello,

I am new to Sencha Touch, but I am very excited about it.
As my first application I would like to make a little app with the posts of my wordpress site. I am using a JSON API plugin to get the JSON. http://wordpress.org/extend/plugins/json-api/


I use a template to show the posts

var postsComponent = new Ext.Component({
title: 'Posts',
scroll: 'vertical',
tpl: [
'<tpl for=".">',
' <div>',
' <p>{title}</p>',
' </div>',
'</tpl>'
]

});

getPosts();


And here I get the data for my template

getPosts = function(){

Ext.util.JSONP.request({
url: 'http://winckelmans.net/wordpress/?json=get_recent_posts',
callback: function(data){
postsComponent.update(data.posts);
}
});

}
getPosts();

But it seems like the callback function is never executed.
What am I doing wrong?

Thanks,
Vincent

rudiboot
14 Feb 2011, 6:01 AM
Ext.util.JSONP.request({
url: 'http://your-url.com/api/get_recent_posts/',
callbackKey: 'callback',
callback: function(data) {
var posts = data.posts;;
updates.update(posts);
}
});

Vinzcent
15 Feb 2011, 12:59 AM
Thank you
when I use http://your-url.com/api/get_recent_posts/ as url, it works. Weird

kennyp
28 Jul 2011, 11:21 AM
Hi guys,
I'm wondering if you'd be willing to share your learnings & even example files around using Wordpress, JSON & Sencha Touch to create apps.

I'm looking to create an app using this method (then hopefully compiling into a native app using PhoneGap) for a non-profit over the next couple months, as both a personal challenge & to help them in their mission. Wordpress (with the JSON API) just seems like such an obvious content repository.. would be really cool to prove it out.

Would you guys be game to share (ideally template files, but even just wisdom or pointers)? Of course, anything I end up using & modifying, I'll share back with you.

Looking forward to hearing from you!

Kenny

Jeronimo79
21 Dec 2011, 10:53 PM
Hey Guys,

I'm pretty new to JS and ST and want to create an app for my wordpress blog. I installed the JSON API too but not sure or well enough to use it in ST. It would be really nice to get some further informations how to handle the JS in ST to get a view of my posts. Especially a sample code would be awesome!

Thanks!!!

Vinzcent
24 Dec 2011, 3:29 AM
I think it shoukd be something like this:



Ext.setup({ onReady: function() {


Ext.regModel('Posts', {
fields: ['id', 'type', 'slug', 'url', 'status', 'title', 'content', 'date']
});

var store = new Ext.data.JsonStore({
model : 'Posts',
proxy: {
type: 'scripttag',
url : 'http://wordpressblog.url.net/?json=get_recent_posts',
reader: {
type: 'json',
root: 'posts'
}
}
});
store.load();

var list = new Ext.List({
itemTpl : '{title} <span class="date">{date}</span>',
store: store
});

var listPanel = new Ext.Panel({
title: 'All Posts',
fullscreen: true,
dockedItems: [
{
dock : 'top',
xtype: 'toolbar',
title: 'My blog'

}],

items:
[list]
});




}
});

StewartWeill
12 Jun 2012, 1:57 PM
I'm having the same confusion as Vinzcent, I get no errors, but no data either. Should I be using a script to tease out the var/value pairs in the array?

Forgive me but I am noob.

zrmedia
6 May 2014, 1:57 AM
I just doing with sencha 1 week and try make a app for my website. But i have a problem with paging and load more content if you work with wordpress json api. you must change url like this:/api/get_category_posts/?id=1&page=1 to /api/get_category_posts/?id=1&page=2 to get data from page 2.Anybody here can help me for problem. Thanks.