1

hi im building application and i need to store data in txt file and retrieve it the data is object like this .. .

[
  {
    "key": 0,
    "id": 1,
    "number": "1001",
    "name": "سلعة ملموسة",
    "offer_end_date": null,
    "offer_start_date": null,
    "components": [],
    "quantity": "9",
    "product": {
      "id": 1,
      "name": "سلعة ملموسة",
      "number": "1001",
      "product_id": null,
      "foreign_name": "Product",
      "can_be_sold": 1,
      "can_be_purchased": 1,
      "can_be_rented": 1,
      "available_on_pos": 1,
      "pos_quick_lunch": 1,
      "available_on_manufacture": 1,
      "product_category_id": 1,
      "product_unit_type_id": null,
      "location_id": null,
      "area_id": null,
      "discount_value": 10,
      "balance": null,
      "smallest_unit_id": 1,
      "smallest_unit_barcode": null,
      "smallest_unit_selling_price": 10,
      "smallest_unit_cost": null,
      "smallest_unit_selling_price_above": null,
      "smallest_unit_selling_price_above_price": null,
      "tax_value": 16,
      "state_id": 1,
      "warehouse_id": null,
      "product_type_id": 1,
      "product_policy_id": null,
      "tax_user_id": null,
      "user_id": null,
      "get_specification_on_lines": null,
      "is_products_has_expire_date": 1,
      "is_products_has_patch_number": 1,
      "is_products_has_serial_number": 1,
      "offer_end_date": null,
      "offer_start_date": null,
      "last_purchase_date": null,
      "last_purchase_purchase": null,
      "last_purchase_price": null,
      "last_purchase_discount": null,
      "created_by": null,
      "deleted_by": null,
      "approved_by": null,
      "approved_date": null,
      "approved_state_id": null,
      "note": null,
      "created_at": "2022-03-04T06:52:16.000000Z",
      "updated_at": "2022-03-04T06:52:16.000000Z",
      "deleted_at": null,
      "get_pos_product_componentss": [],
      "get_pos_product_components": [],
      "get_smallest_unit_id": {
        "id": 1,
        "name": "حبة",
        "foreign_name": "unit",
        "number": "1",
        "created_by": 1,
        "deleted_by": null,
        "approved_by": null,
        "approved_date": null,
        "approved_state_id": null,
        "note": null,
        "created_at": "2022-03-04T06:52:15.000000Z",
        "updated_at": "2022-03-04T06:52:15.000000Z",
        "deleted_at": null
      },
      "get_product_offers": []
    },
    "smallest_unit_selling_price": 10,
    "smallest_unit_selling_price_above": null,
    "smallest_unit_selling_price_above_price": null,
    "discount": 0,
    "allowed_discount": 10,
    "tax_value": 16,
    "unit": "حبة",
    "smallest_unit_id": 1,
    "note": null,
    "active": 1,
    "price": 104.39999999999999
  }
]

now this object i need to store it in file called text.txt how can i store the object inside the file .. and how can i retrieve the data using JavaScript .. thanks .. ive found solutions thats i can put the object in cookies but my problem with cookies they only allowing 4kb of data

4
  • 1
    As it is now, your data is about 2.7kB, therefore the 4kB limit should not be an issue. Alternatively, you can use local storage (developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) which should have a limit of 5MB per app. Commented Mar 4, 2022 at 13:40
  • this is just sample sometimes its 100kb of data Commented Mar 4, 2022 at 13:43
  • I am not sure about that you can do anything like that without a database. Maybe with some kind of hash algorithm you can reduce the size. Commented Mar 4, 2022 at 13:47
  • as @secan says i used localstorage and everything working so good thanks for all Commented Mar 4, 2022 at 13:51

1 Answer 1

2

never mind i found this solution .. first of store data in localStorage like this ..

 localStorage.setItem("orders", JSON.stringify(this.orders));

then access it like this ..

var orders = JSON.parse(localStorage.getItem('orders'));
console.log(orders);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.