0

我在 NODJS 中做了一个简单的网络服务器。网络浏览器即 firfox 将在连接到http://localhost:8888/. 但是 enyon Web 服务 onSuccess 回调显示来自 inResponse 的空字符串。我创建了一个静态网页,并从我的本地 hypache 服务器很好地加载了它。为什么 enyo 不会总是从 nodejs 发送的东西中显示 w null ?

网络服务器

http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}).listen(8888);

我编写了一个简单的 enyo 程序,当您按下按钮时,它会执行 Web 服务并在警报框中显示结果

enyo.kind({
name: "MyApps.MainApp",
kind: enyo.VFlexBox,

// comment code to load in data gfrom service
components: [
{name: "getName", kind: "WebService",
onSuccess: "gotName",
onFailure: "gotNameFailure",
url: "http://localhost:8888/"
},

{kind: "PageHeader", content: "Enyo FeedReader"},
{name:"curValue", content:("Sample Text")},
{kind: "Button", caption: "Action", onclick: "btnClick"} ],

// functions go here
create: function()
{
// call the default creat then do our stuff
this.inherited(arguments);
this.$.getName.call();
},

// Show output of server,
gotName: function(inSender, inResponse) {
this.$.button.setCaption("Success");
alert(inResponse );
},


// go here if it cold not connect to server
gotNameFailure: function(inSender, inResponse) {
this.$.button.setCaption("Failure"); },

// call the server
btnClick: function() {

this.$.getName.call(); }
});

泰德

4

1 回答 1

0

您是否有理由需要编写自己的 Web 服务?enyo.WebService 类型已经供您使用。

如果您确实需要自己的,我建议您查看以下示例项目中的服务是如何实现的:https ://github.com/palm/txjs-fortunecookie

于 2012-01-13T16:54:08.170 回答