Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8602533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:06:31+00:00 2026-06-12T02:06:31+00:00

Trying to create a Sencha-Touch-2 app syncing to a Node.js server; code below. The

  • 0

Trying to create a Sencha-Touch-2 app syncing to a Node.js server; code below.
The server uses another port on the same IP, so this is cross-domain.
(The server uses Mongoose to talk to a MongoDB back-end (not shown))

  • Using a JSONP Proxy as shown can read data from the server but breaks when writing:
    “JSONP proxies can only be used to read data”.
    I guess the JSONP Proxy writer config is just to write the query and isn’t used to write sync (save).

  • Sencha docs state an Ajax proxy can’t go cross-domain, even though a
    Cross-domain Ext.Ajax/Ext.data.Connection is discussed in the Sencha forums:
    http://www.sencha.com/forum/showthread.php?17691-Cross-domain-Ext.Ajax-Ext.data.Connection

  • I have found several ways to do a (cross-domain) JSON post (e.g. Mobile Application Using Sencha Touch – JSON Request Generates Syntax Error)
    but don’t know how to integrate this as a writer in a proxy which syncs my store.
    Sencha Touch: ScriptTagProxy url for create/update functionality
    seems to offer pointers, but this is ajax and apparently unsuited for cross domain.

I’ve been reading this forum and elsewhere for a couple of days, but I seem to be stuck. Any help would be much appreciated.

Node.js and restify server

var server = restify.createServer({
  name: 'Server',
  key: fs.readFileSync(root+'/'+'privatekey.pem'),
  certificate: fs.readFileSync(root+'/'+'certificate.pem')
});

server.use(restify.bodyParser());
server.use(restify.queryParser());

function getMessages(req, res, next) {
  Model.find(function (err,data) {
    res.setHeader('Content-Type', 'text/javascript;charset=UTF-8');
    res.send(req.query["callback"] + '({"records":' +  JSON.stringify(data) + '});');
  });
}

function postMessage(req, res, next) {//not yet tested
  var obj = new Model(); 
  obj.name = req.params.name;
  obj.description = req.params.description;
  obj.date = new Date();
  obj.save(function (err) {
        if (err) throw err;
        console.log('Saved.');
        res.send('Saved.');
  });
}

server.post(/^\/atapp/, postMessage);
server.get(/^\/atapp/, getMessages);

server.listen(port, ipaddr, function() {
    console.log('%s: secure Node server started on %s:%d ...', Date(Date.now()), ipaddr, port);
});

Sencha Touch 2

Model

Ext.define('ATApp.model.User', {
    extend: 'Ext.data.Model',
    config: {
        fields: [
            { name: 'name',  type: 'string' },
            { name: 'description', type: 'string' },
            { name: 'date',  type: 'date' },
            { name: '_id' }
...

Store

Ext.define('ATApp.store.Data', {
    extend: 'Ext.data.Store',
    requires: [
        'ATApp.model.User',
        'Ext.data.proxy.JsonP'
    ],
    config: {
        autoLoad: true,
        model: 'ATApp.model.User',
        storeId: 'Data',
        proxy: {
            type: 'jsonp',  
            model: 'ATApp.model.User',
            url: 'https://192.168.2.45:13017/atapp',
            reader: {
                type: 'json',
                idProperty: '_id',
                rootProperty: 'records',
                useSimpleAccessors: true
            },
            writer: {
                type: 'json',
                allowSingle: false,
                encode: true,
                idProperty: '_id',
                rootProperty: 'records'
...

Controller

onNewDataRecord: function (view) {
                        console.log('newDataRecord');
                        var now = new Date();
                        var record = Ext.create('ATApp.model.User', {
                            date: now,
                            name: '..',
                            description: '..'
                            });
                        var store = Ext.data.StoreManager.lookup('Data')
                        record.setProxy(store.getProxy());
                        store.add(record);
                        this.activateEditor(record);
                    },
...
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T02:06:33+00:00Added an answer on June 12, 2026 at 2:06 am

    In Sencha-Touch-2 apps, the browser prohibits cross-domain AJAX calls (which violate the same-origin security policy). This pertains to different domains, different IP addresses and even different ports on the same IP address. JSONP circumvents this partly by fetching/reading data encapsulated in a script tag in a newly initiated HTTP GET message. In this way the Sencha-Touch-2 JSONP proxy can load a store (fetch/read) from a (cross domain) server. However, the JSONP proxy cannot write data. In 1 and 2 an approach is described which I have adapted.

    My solution uses the JSONP proxy to fetch data, but not to store (which it can’t). Instead, new records, and records to be saved or deleted are communicated with the server in a newly initiated HTTP GET message. Even though only HTTP GET is used, the server accepts message get (described in the question, above), put, del and new. Get is used by JSONP store/proxy load().

    Node.js Server

    //routes
    server.get(/^\/atapp\/put/, putMessage);
    server.get(/^\/atapp\/get/, getMessages);
    server.get(/^\/atapp\/del/, delMessage);
    server.get(/^\/atapp\/new/, newMessage);
    
    function newMessage(req, res, next) {    
        var obj = new Model();                  // Mongoose create new MongoDB object
        obj.save(function (err,data) {
            var x = err || data;
            res.setHeader('Content-Type', 'text/javascript;charset=UTF-8');
            res.send(req.query["callback"] + '({"payload":' +  JSON.stringify(x) + '});');
        });                                     // send reply to Sencha-Touch 2 callback
    }
    
    function putMessage(req, res, next) {    
        var q = JSON.parse(req.query.data);     // no reply: add error recovery separately
        var obj = Model.findByIdAndUpdate(q.key,q.val);  
    }
    
    function delMessage(req, res, next) {
        var key = JSON.parse(req.query.data);
        Model.findByIdAndRemove(key);       // no reply: add error recovery separately
    }
    

    Sencha Controller

    New

    onNewDataRecord: function (view) {
        var control = this;
        Ext.Ajax.Crossdomain.request({
            url: 'https://192.168.2.45:13017/atapp/new',
            rootProperty: 'payload',
            scriptTag: true, // see [1](http://code.google.com/p/extjsdyntran/source/browse/trunk/extjsdyntran/WebContent/js/3rdparty/Ext.lib.Ajax.js?r=203)
            success: function(r) { // process synchronously after response
                var obj = r.payload;
                var store = Ext.data.StoreManager.lookup('Data');
                var key = obj._id // MongoDB document id
                store.load(function(records, operation, success) { // add new record to store
                                var ind = store.findBy(function(rec,id) {
                                                    return rec.raw._id==key;
                                                }); // identify record in store
                                var record = store.getAt(ind);
                                control.onEditDataRecord(view,record);
                            }, this);
            }
        });
    

    Save

    onSaveDataRecord: function (view, record) {
        rec = {key:record.data.id, val: {}} // save template
        var i; for (i in record.modified) rec.val[i]=record.data[i];
        var delta = Ext.encode(rec); // only save modified fields
        Ext.Ajax.Crossdomain.request({
            url: 'https://192.168.2.45:13017/atapp/put',
            params: {
                data: delta,
            },
            rootProperty: 'payload',
            scriptTag: true, // Use script tag transport
        });
    },
    

    Delete

    onDelDataRecord: function (view, record) {
        var key = record.data.id;
        Ext.Ajax.Crossdomain.request({ // delete document in db
            url: 'https://192.168.2.45:13017/atapp/del',
            params: {
                data: Ext.encode(key),
                format: 'json'
            },
            rootProperty: 'payload',
            scriptTag: true, // Use script tag transport
        });
        record.destroy(); // delete record from store
    },
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to sencha touch and I am trying to create a container divided
I am trying to create a form with Sencha Touch that will create a
I am trying to create a vertical slider using sencha touch 2 for a
I am trying to create a form through sencha touch that simply takes the
I'm new in Sencha Touch and I'm trying to create a TabPanel with a
I have just started building app with sencha touch 2 I was trying to
I'm new to Sencha Touch 2, and trying to learn it by following this
I've been trying create this simple ish to-do list web app using JavaScript &
I took this code from another question and now I'm trying to get the
I'm building an app using Sencha Touch and PhoneGap (aka Apache Cordova). I'm trying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.