繁体   English   中英

将请求从Sencha touch应用发送到Node.js服务器

[英]Send request from Sencha touch app to Node.js server

我最近开始使用Sencha Touch进行编码,我想制作一个带有按钮的简单应用程序,该请求将请求发送到Node.js服务器。 然后,我想显示一条简单的消息,以查看服务器已收到请求。

我尝试了Ext.Ajax.request和Ext.data.JsonP.request,但是没有成功...我进行了很多搜索并尝试了很多事情。

现在我的代码应用程序端看起来像:

    launch: function() {

    var button = Ext.create('Ext.Button', {
        iconCls: 'action',
        ui: 'action',
        handler: function() {
            Ext.Ajax.request({
                url: 'localhost:8080',
                success: function (response) {
                    Ext.Msg.alert('Success');
                },

                failure: function (response) {
                    Ext.Msg.alert('Failure');
                }
            });
        },
    });

    Ext.Viewport.add(Ext.create('Ext.Container', {
        fullscreen: true,
        layout: {
            type: 'vbox',
            pack: 'center',
            align: 'center'
        },
        items: [
            {
                html: 'Send The Request'
            },
            {
                items: [button]
            }
        ]
    }));
},

而服务器端是:

var http = require('http');
var url = require('url');

var server = http.createServer(function(request, response) {
    var page = url.parse(request.url).pathname;
    console.log(page);
    response.writeHead(200);
});

server.on('request', function(request, response) {
    response.end('42');
});

server.listen(8080);

我知道这些代码很烂,请放心,我是javascript新手。

提前致谢

localhost:8080将无法在手机上部署该应用程序,因为它将以手机本身为目标(但可以从浏览器进行测试)。 url也应该也需要协议(http://)。

您需要对此进行调试,并确定请求失败的时间点。

您可以尝试从节点进行console.log'ing,以查看是否收到请求。 或者,在Chrome中打开应用程序,然后使用检查器的“网络”标签查看请求是否曾经发送过,以及是否发送了响应(如果有)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM