Sencha touch xml reader - sencha-touch

I have a problem with sencha touch xmlreader.
find my code below
Ext.regModel('User', {
fields: ['id', 'name', 'email']
});
var feedStore = new Ext.data.Store({
model: 'User',
proxy: {
type: 'ajax',
url : '192.168.248.1/notizie.xml',
reader: {
type: 'xml',
record: 'user'
}
}
});
notizie.xml
1
E
f
feedStore is always empty.
Could anyone can discover the reason?
Regards,
Kevin

Yes, if you use JSON then you can use scripttag proxy or if you use native app wrapper like phonegap than you don't get that cross domain security issue.

I solved the issue!
If you use the ajax you just can send requests inside your domain.
I pubblished notizie.xml and index.html on the server.
My question is there is a way using sencha touch to make a request outside your domain?
Ragards,
Carmelo

Only JSONP supports external domains. No way to use xml, only well formed json+callback. Look for ScriptTagProxy, it works pretty well, but only if you can change the service to use jsonp.
It's common policy with all current browsers. You can read more about this from wikipedia

Related

get an jpg image from a mobilefirst http adapter

im working in a mobilefirst adapter (6.3) that need to pass an image from an url that is in the internarl network file system(example :http://www.up.edu.pe/RED_Compartir/facebook.png) but i cant get the data correctly, the img data isnt in the text variable:
Here is my server side code:
function getImage(id){
var input = {
method : 'get',
returnedContentType : 'plain',
path : '/someUrl/someUrl2/'+id+'.jpg'
};
return {
out: Base64.encode(WL.Server.invokeHttp(input).text)
};
}
Here is my client code to process de image:
function getImageFrom() {
execMobileFirstAdapter("adapterName", "method", ["parameter"]).then(function (data){
WL.Logger.debug("OK")
var imageBase = data.invocationResult.out;
document.getElementById('imageServer').setAttribute( 'src', 'data:image/jpeg;base64,'+ imageBase );
}).fail(function(data){
WL.Logger.debug("error");
})
}
Is there a way to return the base64 from a jpg image from a mobilefirst adapter?
Ive used this example:
https://www.ibm.com/developerworks/community/blogs/mobileblog/entry/ibm_worklight_adapter_accessing_an_image?lang=en
and Works perfectly but i need to do this only with JavaScript in the server. is this posible?
Is there a way to return the base64 from a jpg image from a
mobilefirst adapter?
I've used this example:
https://www.ibm.com/developerworks/community/blogs/mobileblog/entry/ibm_worklight_adapter_accessing_an_image?lang=en
and Works perfectly but i need to do this only with JavaScript in the
server. is this possible?
The easiest approach is in fact to implement it the way the example does it in the article you've provided.
The only other way is to find a JavaScript lib that does base64 encoding and try to add this lib to the adapter and then use it.
Note that JavaScript adapters do not support adding additional files to the adapter, so that means you need to take the entire implementation of whichever lib you'll find and put it inside your adapter code. Not so nice. Also does not guarantee it'll work.
Additionally, are you calling your adapter from inside a Cordova plug-in? That was strange. Why? Why not just use the WL.Client.invokeProcedure API... just like in the article...

how to connect MySql db with sencha touch application

I'm new to Sencha and have been reading tons of documentation but what I haven't been able to find is the proper way to make a connection to my MySQL DB, Could someone point me in the right direction.
You don't really "connect" to a database with a Sencha Touch application. You have to create some kind of API for it to interact with. So wherever you database is hosted you might have a file like "users.php", inside that file you would have code that pulls whatever you need from the database (or inserts data into the database) and then outputs it to the browser in a JSON format.
Then in your Sencha Touch application you would make an Ajax request to that page like this:
Ext.Ajax.request({
url: 'https://www.example.com/users.php',
method: 'post',
params: {
data: data
},
success: function(response){
}
});
or you could define a proxy in your models or stores like this:
proxy: {
type: 'ajax',
api: {
create: 'http://example.com/users.php?action=create',
read: 'http://example.com/users.php?action=read',
update: 'http://example.com/users.php?action=update',
destroy: 'http://example.com/users.php?action=destroy'
},
reader: {
rootProperty: 'users'
}
}
I've written a pretty in depth tutorial if you want some more details: http://www.joshmorony.com/part-1-sencha-touch-email-facebook-log-in-system-with-php-mysql-backend/

Sending Additional Info with a Typeahead Query

I'm using Bootstrap 3.2.0 and jQuery 2.1.1.
I've implemented typeahead search suggestions and now wanted to go a step further. I am using the remote method and was hoping to send more than just the query to the PHP that will run a SQL script:
$(function() {
var productEngine = new Bloodhound({
datumTokenizer: function (datum) { return Bloodhound.tokenizers.whitespace(datum.value); },
queryTokenizer: Bloodhound.tokenizers.whitespace,
limit: 10,
remote: { url: 'php/product_suggest.php?storeid='.concat(localStorage.getItem('store_id'), '&query=%QUERY') }
});
productEngine.initialize();
$('input#product_suggest').typeahead(null, {
displayKey: 'value',
source: productEngine.ttAdapter()
});
});
I've also tried building the URL and saving as a variable. Then attempting to call that variable in the remote.
remote: { url: builtURL }
As I don't particularly know how this url is being parsed and used or how the %QUERY is being added, I'm assuming my issue lies in my lack of knowledge around how typeahead is processing this.
I thought this would be a fairly common request, but Google has let me down. Anyone have any suggestions or can point me towards examples of sending additional info with a typeahead query?

How to update Rails partials at set intervals with $.ajax()?

I'm building a sort-of clone of CoverItLive in Rails 3.1 and want to have the stream of comments automatically update. I'm using a partial in the view to display comments. There's a lot of info out there on doing UJS and AJAX wit forms or buttons or links in Rails, but I can't find any specific examples for what I need to do.
I'm assuming that .ajax() is the best approach, but I've never used it before and not sure if I need to provide .js.erb files when using this particular function? Could I just have the controller send JSON back to the client and go from there, or is there a better approach in rails?
This is what I'm thinking so far, based on what I read at another question:
setInterval(function() {
$.ajax({
type: 'GET',
url: ''<%= comments_path(:json) %>'',
data: {
data: "comments_data"
},
cache: false,
success: function(result) {
if (result == "true"){
alert("true");
}else{
alert("false");
}
}
});
}, 3000);
As an alternative you should look into Private Pub, a gem that Ryan Bates has put togeather. See a screencast about it on railscasts.
The trouble with your solution is now often you server will be hit unnecessarily, i guess it depends on the number of concurrent users you thing will be viewing this page.
if you do go down your route the .js.erb could just have a somthing like this in it:
$('#id_of_area_to_replace').html("<%= escape_javascript(render"comments/index") %>")
This would replace the whole area else you could just append new comments to the bottom of the area

How to set JSONP calls in sencha touch to Synchronous?

I'm creating a mobile app using sencha touch & facing a problem in asynchronous call of the JSONP I use, and I think I can solve it using synchronous call just like Ajax in Extjs 4.x :
Ajax synchronous in Extjs 4.x
Is it possible to set synchronous calls in JSONP?
or is there an override to achieve that?
Thanks in Advance :)
I looked into this quite extensively a while back, and found that it is not possible. This is because of the script tag hack used in JsonP. The only reason to use JsonP is to get around the cross-domain issues. To get around this using regular Json and set this header on your website specifying the sites that are allowed to make calls to this site.
Access-Control-Allow-Origin: http://foo.example
categories = new Ext.data.Store({
model: 'categories',
autoLoad: true,
proxy: {
type: 'ajax',
url: 'http://localhost/php/server.php?action=catall',
reader: {
type: 'json'
}
}
});
its the json data
[{"catname":"HEALTH","id":"1"},{"catname":"IMAGINE","id":"2"},{"catname":"ENTERTAINMENT ","id":"3"},{"catname":"KIDS","id":"4"},{"catname":"LOCAL","id":"5"},{"catname":"TRAVELLER ","id":"6"},{"catname":"INTERNET ","id":"7"}]