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..
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..
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"]
.
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
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!');
}
});
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}');