如何使用jQuery保存AJAX应用程序的状态

时间:2022-10-22 23:30:26

I am just trying to dip my toes in this Ajax thing. I have a very basic question

我只是试图在这个Ajax的东西中浸泡我的脚趾。我有一个非常基本的问题

I have seen the UI plugin(http://interface.eyecon.ro/docs/drag) for jQuery, where you can drag and drop frames, stretch things, animate etc. So basically you get all the desktop features right in your web application.

我已经看过jQuery的UI插件(http://interface.eyecon.ro/docs/drag),你可以在这里拖放框架,伸展东西,动画等等。所以基本上你可以在网络上获得所有的桌面功能应用。

In the desktop world, you can save the state of the objects to a file but how do you save the state of the manipulated objects in jQuery.

在桌面世界中,您可以将对象的状态保存到文件中,但是如何在jQuery中保存操作对象的状态。

For e.g. If I drag a frame in jQuery, or stretch the borders of a div element, how do I save it to a file on the server so that next time, when I open, it remains modified?

对于例如如果我在jQuery中拖动一个框架,或者拉伸div元素的边框,我该如何将它保存到服务器上的文件中,以便下次打开时它会被修改?

2 个解决方案

#1


6  

Collect the state into an object, serialize it to JSON, do an HTTP POST using AJAX to a script on your server which saves it appropriately.

将状态收集到一个对象中,将其序列化为JSON,使用AJAX对服务器上的脚本执行HTTP POST,以便适当地保存它。

Load it with the reverse method (you can skip the AJAX and print the JSON straight into your page as it loads though)

使用反向方法加载它(您可以跳过AJAX并在加载时将JSON直接打印到页面中)

#2


1  

Yes Nilesh - the height() and width() methods. I'm not aware of a native method that provides positional data, although there may well be a plug-in; failing that, some raw javascript should suffice some raw javascript should suffice.

是Nilesh - height()和width()方法。我不知道提供位置数据的本机方法,尽管可能有一个插件;如果失败了,一些原始的javascript应该足够一些原始的javascript就足够了。

#1


6  

Collect the state into an object, serialize it to JSON, do an HTTP POST using AJAX to a script on your server which saves it appropriately.

将状态收集到一个对象中,将其序列化为JSON,使用AJAX对服务器上的脚本执行HTTP POST,以便适当地保存它。

Load it with the reverse method (you can skip the AJAX and print the JSON straight into your page as it loads though)

使用反向方法加载它(您可以跳过AJAX并在加载时将JSON直接打印到页面中)

#2


1  

Yes Nilesh - the height() and width() methods. I'm not aware of a native method that provides positional data, although there may well be a plug-in; failing that, some raw javascript should suffice some raw javascript should suffice.

是Nilesh - height()和width()方法。我不知道提供位置数据的本机方法,尽管可能有一个插件;如果失败了,一些原始的javascript应该足够一些原始的javascript就足够了。