I still can’t seem to get this to work.I’ve tried string arrays object arrays dictionaries. I might be formatting my JSON incorrectly however I am using the labs_JSON plugin. If I remove my data and test the webservice it calls correctly. The : My code looks as follows :
HTML :
<div style="display: block; float: left;">
<asp:Repeater ID="rptMenuRecipeCategories" runat="server">
<HeaderTemplate>
<div class="recipeChecklistHeader">Menu Recipe Categories</div>
<ul id="menuRecipeCategories" class="connectedSortable">
</HeaderTemplate>
<ItemTemplate>
<li id="item_<%# Container.ItemIndex + 1 %>" recipeCategoryId='<%# Eval("RecipeCategoryID") %>' >
<%# Eval("RecipeCategory") %>
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
</div>
<div style="display: block; float: left">
<asp:Repeater ID="rptAvailableMenuRecipeCategories" runat="server">
<HeaderTemplate>
<div class="recipeChecklistHeader">Available Menu Recipes</div>
<ul id="availabeMenuRecipeCategories" class="connectedSortable">
</HeaderTemplate>
<ItemTemplate>
<li id="item_<%# Container.ItemIndex + 1 %>" recipeCategoryId='<%# Eval("RecipeCategoryID") %>'>
<%# Eval("RecipeCategory") %>
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
</div>
JS:
$(function () {
$("#menuRecipeCategories, #availabeMenuRecipeCategories").sortable({
connectWith: '.connectedSortable',
update: function (ev, ui) {
//var result = $('#menuRecipeCategories').sortable('toArray');
//updateSequenceNumber(result);
}
}).disableSelection();
});
//This is currently raised through a button click event function persistRecipeCategoriesToJSON() { var items = $('#menuRecipeCategories').sortable('toArray'); var dictionaryData = ''; var index = 0; var itemArray = new Array();
for (i = 0; i <= items.length - 1; i++) {
if (items[i].length == 0)
continue;
var item = $('#' + items[i])[0];
var recipeCategoryId = item.attributes["recipeCategoryId"].nodeValue;
itemArray[i] = recipeCategoryId;
}
persistPositionUsingAjax($.json.encode(itemArray));
}
$(document).ready(function () {
$.ajaxSetup({
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json"
});
});
function persistPositionUsingAjax(jsonData) {
var webServiceURL = '<%=ResolveUrl("~/UserControls/MenuRecipeChecklistService.asmx")%>' + '/UpdateMenuRecipeChecklist';
$.ajax({
// This is page.name/MethodName
url: webServiceURL,
// This is the data (method arguments)
data: jsonData,
// This is the handler for success.
success: function (msg) {
alert('success');
}
});
}
JSON :
["1","2"]
Webservice:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string UpdateMenuRecipeChecklist(*INPUT TYPE TO GO HERE*)
{
return "";
}
**Ok guys. I've resolved this issue. It seemed The JSON was being formatted incorrectly with the Json labs plugin. I added this line to my persistRecipeCategoriesToJSON function:
var args = { jsonData: itemArray };
persistPositionUsingAjax($.json.encode(args));
The JSON is then formatted correctly by assigning a name to the object. I then I update the method signature of my webservice to:
public string UpdateMenuRecipeChecklist(string[] jsonData)
and everything then works :) . Thanks to everyone who attempted to help!