我想集成codeigniter和node.js,但我对如何执行感到困惑 node.js和codeigniter。
我已经成功安装并运行了nowjs示例:http://nowjs.com/doc/example
如何访问codeigniter(或任何php框架)的视图文件到node.js.
我有困惑,因为codeigniter使用url http://localhost/xyz
执行,而node.js执行http://localhost:8080/xyz
所以我必须在浏览器中编写哪个url,我可以使用node.js和amp;笨?
答案 0 :(得分:9)
以下是ii如何使codeigniter和nodejs相互通信。
我在http://mydomain.com/controller/function/上运行了我的codeigniter应用程序,我在http://mydomain.com:8080上运行了我的nodejs(nowjs),
用户将使用codeigniter URL,当打开页面时,我在我的CI视图页面上有这个脚本连接到我的Nodejs应用程序,类似于:
<script src="http://mydomain.com:8080/nowjs/now.js"></script>
<script>
$(document).ready(function(){
now.receiveMessage = function(name, message){
$("#messages").append("<br>" + name + ": " + message);
}
// Send message to people in the same group
$("#send-button").click(function(){
now.distributeMessage($("#text-input").val());
$("#text-input").val("");
});
now.name = prompt("What's your name?", "");
// on establishing 'now' connection, set server room and allow message sending
now.ready(function(){
// Pick up list of available chatrooms from server and populate dropdown
setServerRoomFromList(now.serverRoomsList);
// By default pick the first chatroom
now.changeRoom($('#server-room').val());
// Connection established and room set; allow user to start sending messages
$("#send-button").removeAttr('disabled');
});
// On change of drop down, clear text and change server room
$('#server-room').change(function(){
$("#messages").html('');
now.changeRoom($('#server-room').val());
});
});
// populate the #server-room dropdown
function setServerRoomFromList(roomList){
$('#server-room').empty();
$.each(roomList, function(key, value)
{
$('#server-room').
append($("<option></option>").
attr("value",key).
text(value));
});
}
</script>
他们可以很好地互相交谈!!