English 中文(简体)
Ajax网页与数据库的同步化
原标题:Synchronization of ajax webpage with database

数据库和网页在利用“jax”电话改变数据时实现同步的最佳途径是什么? 举一个例子,我要说的是,我有增加评论的一种形式,我希望这样做是同步的。 因此, 我制定了一份联合材料法典,将这一表格提交一个数据库。 在不必更新网页的情况下向用户展示这一新数据的最佳做法是什么? 目前,我可以想到解决这一问题的3个解决办法:

  1. Put JS编码将处理这一数据,并在我们从服务器收到ok后插入该页的适当部分。

  2. 作为服务器的答复,发送了该要素中应显示的所有数据,然后简单地利用联合材料插入所有内容。

  3. Kind of a mix between 1 and 2, as a response from the server send only the processed new piece of data and insert it to the appropriate place.

我不喜欢1年的法典,即我们必须两次执行处理逻辑。 我也不喜欢2。 由于服务器发送的数据的间接费用。 页: 1 我最喜欢这种做法,但是,还有些数据被退回和披露。 我知道这些间接费用可能不会影响该系统在大多数情况下的运作,但我很想知道这一问题是否有任何其他解决办法,以及确保数据齐划一的最佳做法是什么?

最佳回答

You might want to consider using Models and Collections like how backboneJS does it. It s sort of a "local copy of the database". First, your model fetches just a few records for display, like the top 10 things in a todo list. the model has CRUD methods where you can manipulate the data in it.

然后,就座标而言,你有单独的意见守则。 这些看法取决于模型,也符合CRUD,并听取了从现有模块接口或您接口的另一部分可以进行的模型数据改动。 如果部分页面变更数据,其余部分则通知同一模型。 模型可以是什么,它可能代表数据库中一个或一个表格组合。

similarly, that model will have an AJAX sync capability. every data modified in it gets reflected to the server via an AJAX call. when that call completes, you notify all hooked interfaces to update accordingly. since the data is contained in the model, you only need to send changes to the server and listen for a success. as for live data from the server, you can create some polling capability in the model to update it s data. if there s change, notify all hooked interfaces.

问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签