I have a form written below:
<table>
<tr>
<td>Worker Type:</td>
<td><input type="text" id="WorkerTypeTB"/></td>
</tr>
<tr>
<td>Worker Name:</td>
<td><input type="text" id="WorkerNameTB1"/></td>
<td>Worker Position</td>
<td><input type="text" id="WorkerPositionTB1"/></td>
</tr>
<tr>
<td>Worker Name:</td>
<td><input type="text" id="WorkerNameTB2"/></td>
<td>Worker Position</td>开发者_开发百科
<td><input type="text" id="WorkerPositionTB2"/></td>
</tr>
.
.
.
<tr>
<td>Worker Name:</td>
<td><input type="text" id="WorkerNameTBn"/></td>
<td>Worker Position</td>
<td><input type="text" id="WorkerPositionTBn"/></td>
</tr>
<tr>
<td>
<input type="button" id="SaveBTN"/>
</td>
</tr>
</table>
It has one worker type field, and dynamically generated N (WorkerName,WorkerPosition) fields.
What is the best way to send data to AJAX calling ASP.NET page?
I am using following jQuery AJAX:
$.ajax({
type: "POST",
url: "AjaxMethod.aspx",
data: data,
//dataType: "json", ??????
//contentType: "application/json; charset=utf-8" ?????
});
Should I use JSON or some other dataType to send my data to ajax calling page? I would like to optimally format my form data in following manner:
workerType: developer
workers:
workerName1: Jack
workerPosition1: Johnson
workerName2: Joe
workerPosition2: Phillips
...
workerNameN: Walter
workerPositionN: Wolf
How to format this kind of data to JSON if JSON is best dataType to use for sending data to ajax calling page? How to send this JSON object via jQuery AJAX?
How to accept this type of data on server side Page_Load function and how to read it's elements?
Thank you in advance!
This article walks through using ASP.NET, JSON, json2, and jQuery:
Using complex types to make calling services less… complex
精彩评论