0

I want to store page data in a json file and when I click a button i want to send it to a web service. How can I do It. Direct me.

Thanx..

Darshana
  • 2,462
  • 6
  • 28
  • 54

5 Answers5

2

If you use html5, you can use localStorage["any_key"] = "your_json_string" to save your data in the browser and fetch the data by using localStorage["any_key"].

David Rodrigues
  • 12,041
  • 16
  • 62
  • 90
zsxwing
  • 20,270
  • 4
  • 37
  • 59
2

how do you plan to store file on the client? You can serialize the data into json and send it to the desired webservice

here are some useful posts

let me google that for you

Jquery Ajax Posting json to webservice

http://francstratton.com/jQueryAJAXCall.aspx

Community
  • 1
  • 1
Rafay
  • 30,950
  • 5
  • 68
  • 101
0

I store json in input hidden in html

Darshana
  • 2,462
  • 6
  • 28
  • 54
0

You can't store a json file, but if you want to send information in an array to a WebService via jQuery.ajax() you can do it:

// First you construct an array (can be multidimensional)
var arr_data = {
  name: 'John Doe',
  age: 21,
  phones: [ 12345678, 87654321 ]
};

$.ajax('service-page.php', {
  data: arr_data,
  success: function() {
    alert('Content saved!');
  }
});
David Rodrigues
  • 12,041
  • 16
  • 62
  • 90
0

If I understand correct your existing problem you should save the data not in the file, but in the DOM of the page. If you want for example that the saved data will have any association with a button you can use jQuery.data to save the information. For example

// save data as object
$('#myButtonId').data('forMyWebService', { myType: 'test', count: 40 });

or

// save data as JSON string
$('#myButtonId').data('forMyWebService', '{"myType":"test","count":40}');
Oleg
  • 220,925
  • 34
  • 403
  • 798