节点,防爆preSS,Ajax和翡翠例 [英] Node, Express, Ajax, and Jade Example

查看:142
本文介绍了节点,防爆preSS,Ajax和翡翠例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在找一个节点/ EX preSS /玉页面的简单例子使用Ajax调用与客户端和服务器端的code被更新。

I'm looking for a simple example of a Node/Express/Jade page being updated using an Ajax call with both the client and server side code.

我有一个有点麻烦,把他们放在一起在我的头上。

I'm having a bit of trouble putting it all together in my head.

推荐答案

有很多方法可以这样做,这不是显而易见的,你要采取哪一种方法。

There are great many ways this could be done and it's not immediately apparent which approach you want to take.

我想最简单的方案是将添加一些客户端逻辑从服务器上获取的HTML片段,并更新客户端。这是使用jQuery(把它放在一个文件准备块内要连接的情况下)容易实现:

I suppose the simplest scenario would be to add some client-side logic to fetch pieces of html from the server and update the client. This is easily achieved using jQuery (put it inside a document ready block to wire up the event):

$('#button').click(function() {
     $.get('/some/url', {foo: 42}, function(result) {
         $('#target').html(result);
     }
}

这样,所有的HTML是在服务器上生成的,你根本取,并根据需要将其插入到页面。

This way all your html is generated on the server and you simply fetch and insert it into the page as needed.

您也可以从服务器获取JSON和在客户端呈现的HTML,但是这是的途径之一。我强烈推荐给 TodoMVC 一看 - 这是一个待办事项列表应用程序有许多不同的实现(每次使用不同的架构),因此对各种做法和助手库一个很好的学习资源。

You could also fetch json from the server and render the html on the client, but that is one of the alternative approaches. I highly recommend giving TodoMVC a look - it's a todo-list application with many different implementations (each using a different framework) and therefore a great learning resource for the various approaches and helper libraries.

我也建议你动手的Node.js 书。这将帮助你了解路由以及如何开始使用节点。

I'd also recommend the Hands-on Node.js book. It will help you understand routing and how to get started with Node.

这篇关于节点,防爆preSS,Ajax和翡翠例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆