如何使用 AJAX 创建 Json 数据源 .txt 文件?

发布于 2024-08-31 05:36:28 字数 540 浏览 3 评论 0原文

我正在创建一个收集有关客户的标准信息的表单。当用户点击“保存”时,我想创建一个 .txt 文件,用于稍后检索从客户收集的所有数据。我正在使用 DataTables,它是一个 jQuery 插件来显示数据。 .txt 文件将被格式化为保存如下:

{
  "aaData": [
    ["client 1 name", "address", "city", "state", "zip"],
    ["client 2 name", "address", "city", "state", "zip"],
    ["client 3 name", "address", "city", "state", "zip"],
    ...["client x name", "address", "city", "state", "zip"]
  ]
}

其中“aaData”:由 DataTables 使用。这将是 iPhone 应用程序的一部分,因此数据源必须非常小,并且不依赖于与服务器的持续连接,因此本质上是客户端数据源。 .txt 文件在编辑和保存时也必须更新,然后在每次下载时进行替换。

I'm creating a form that collects standard information about customers. When the user hits save, I would like to create a .txt file that would be used to later retrieve all of the data collected from customers. I'm using DataTables which is a jQuery plugin to display the data. The .txt file would be formatted to be saved as such:

{
  "aaData": [
    ["client 1 name", "address", "city", "state", "zip"],
    ["client 2 name", "address", "city", "state", "zip"],
    ["client 3 name", "address", "city", "state", "zip"],
    ...["client x name", "address", "city", "state", "zip"]
  ]
}

Where "aaData": is used by DataTables. This is going to part of an iPhone app, so the data source has to be very small and not reliant on a constant connection to a server, so, essentially, a client-side data source. The .txt file has to also be updated when edited and saved, and then replaced every time it is downloaded.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

诗酒趁年少 2024-09-07 05:36:28

您想在本地(即客户端计算机上)保存 .txt 文件吗?这是不可能的:出于(明显的)安全原因,浏览器的 JavaScript 环境无法访问本地文件系统。您可以将此 JSON 格式的数据保存在 cookie 中(每个 cookie 最大 4 KB),或者在 HTML 5 中使用 本地存储

Do you want to save a .txt file locally (i.e., on the client computer)? That's not possible: for (obvious) security reasons, a browser's JavaScript environment is unable to access the local file system. You can save this JSON-formatted data in a cookie (max. 4 KB per cookie) or, with HTML 5, using localStorage.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文