I am a newbie to programming, so please bear with me.
Background
I have created a jQuery function that picks up the text, top and left coordinates for various text boxes on my page and I wish to pass all this information using an AJAX POST to a web service written in C#.
I have been successful in passing this data for one textbox to the web service method and inserted a record into a SQL database (I won't go into how long this has taken me!).
In order to write data for multiple text boxes, I am using a jQuery function containing an array of objects, for which I have taken inspiration from the first option in the following post: Jquery multidimensional arrays
Here's my code:
function Note(noteText, topCoord, leftCoord) {
return {
noteText: noteText,
topCoord: topCoord,
leftCoord: leftCoord
}
var noteData = [];
function SaveNote() {
{'input').filter("notes").each(function(index) {
var noteText = ($this)).val();
var coord = ($this)).offset();
var topCoord = coord.top;
var leftCoord = coord.left;
noteData.push(Note(noteText,topCoord,leftCoord));
var jsonText = JSON.stringify({ noteData : noteData});
});
Alerting variable jsonText I receive the following:
{"noteData":[{"noteText":"This is note text" ; "topCoord":23.33 ; "leftCoord":12.23}, {"noteText":"Note text 2" ; "topCoord":23.33 ; "leftCoord":12.23}]}
The Problem:
- This is great! But how can I 'decode' this data within the web method in C# so that I can access each piece of data to eventually write a record to a SQL database for each Note 'object'.
I hope this makes sense. Thank you in advance.