J'ai la méthode Web ASP.net suivante:Comment appeler la méthode web ASP.net avec le paramètre Array de jQuery Javascript?
[WebMethod]
public static string SaveUserNew(string id, string[] roles)
{
doStuff(id, roles);
}
J'appelle ce code de jQuery code Javascript, mais je ne connais pas la syntaxe pour passer un tableau. Habituellement, j'écris du code jQuery pour appeler des méthodes web qui ressemblent à ceci:
$.ajax({
type: "POST",
url: "someUrl.aspx?webmethod",
data: '{"foo":"fooValue"}',
contentType: "application/json;",
dataType: "json",
}
Veuillez apporter quelques précisions à ce sujet.
Mise à jour: Voici un exemple de code sans tableaux qui fonctionne:
[WebMethod]
public static string SaveUserNew(string id)
{
return "0";
}
var jdata = '{ "id": "3TWR3"}';
$.ajax({
type: "POST",
url: "UserMgmt.aspx/SaveUserNew",
data: jdata,
contentType: "application/json;",
dataType: "json",
traditional: true
}
});
Mon intention est d'écrire un code dans un style similaire où je passe des tableaux à ma méthode Web.
double possible de [Passage tableau de chaînes à WEBMETHOD avec nombre d'arguments variables en utilisant jQuery AJAX] (http://stackoverflow.com/questions/7971393/passing -array-of-strings-to-webmethod-avec-variable-number-of-arguments-using-jq) – weir