Hi; i have a question for calling wcf service. how to fill data array Key/Value pair? How to efficiently send collaction via jquery?
$('#btn').click(function () {
var val = [];
var names = [];
$('#cblist :checkbox:checked').each(function (i) {
val[i] = $(this).val();
names[i] = $(this).attr('name');
});
});
<div id="cblist">"Dynamically filling"</div>
<br />
<input type="button" class="btn" value="AddParameter" id="btn" name="btnDelete" />
i dislike this below method(but below codes not working)Do you prefer this? if you prefer, how can i write correct coding?
for (var i in names,val) data.push({ name: names[i], value: val[i] });
$.ajax({
url: "echo/json/",
data: data,
dataType: "json",
traditional: true,
success: function(msg){alert(msg)}
});
But i can not: i dislike call wcf service each array items. i will write 2 kind of wvf service:
First one is :
Service1.svc/AddParameter:
public void AddParameters(int id, params string[] names, params string[] values)
{
//dosomething
}
Second one is :
Service2.svc/AddParameter:
public void AddParameters(int id, NameValueCollection NameswithValues)
{
//dosomething
}
Summary; i want to prepare data array for json format: data{ id: 1, name1:value1, name2,value2……….n}, an then call Service1 and Service2. which one is efficient method?
My main question is : how to write efficient json ajax method which ic calling Service1.svc and Service2.svc?
Try this instead
Then just pass data in your ajax call.