我最近開始使用Sencha Touch進行編碼,我想用一個發送請求到Node.js服務器的按鈕做一個簡單的應用程序。然後,我想顯示一條簡單的消息來查看服務器收到請求。發送請求從Sencha觸摸應用程序到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的。
在此先感謝
我忘了指定用Wamp測試它(用於應用程序端)。在localhost/MyApp的應用程序和localhost的服務器:8080 – Gniar