试图使用NODEJS和enyo作为前端创建Web服务
问题描述:
我在NODJS中做了一个简单的网络分类器。当连接到http://localhost:8888/
时,web浏览器即firfox将显示出世界的和谐。但是,enyon web服务onSuccess回调会显示来自inResponse的空字符串。我创建了一个静态网页,enyo通过我的本地hypache服务器加载了它。为什么不会enyo总是显示w null从nodejs发送的东西??试图使用NODEJS和enyo作为前端创建Web服务
Web服务器
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(); }
});
结果泰德
答
是否有理由需要编写自己的Web服务? enyo.WebService类已经在那里供您使用。
如果你真的需要你自己,我建议考虑看看服务是如何在下面的示例项目实施:https://github.com/palm/txjs-fortunecookie
谢谢你的链接,仍然无法正常工作,但在web浏览器领事显示“XMLHttpRequest无法加载http:// localhost:3000 /。原因http:// localhost:81不被Access-Control-Allow-Origin允许。”任何想法? – 2012-01-14 15:32:21