I have the following jquery code to call a webmethod in an aspx page
$.ajax({
type: "POST",
url: "popup.aspx/GetJewellerAssets",
contentType: "application/json; charset=utf-8",
data: '{"jewellerId":' + filter + '}',
dataType: "json",
success: AjaxSucceeded,
error: AjaxFailed
});
and here is the web method signature
[WebMethod]
public static string GetJewellerAssets(int jewellerId)
{
This works fine.
But now I need to get two parameters passed to the web method
the new web method looks like this
[WebMethod]
public static string GetJewellerAssets(int jewellerId, string locale)
{
}
How do I change the client code to successfully call this new method signature ?
EDIT:
The following 2 syntaxes worked
data: '{ "jewellerId":' + filter + ', "locale":"en" }',
and
data: JSON.stringify({ jewellerId: filter, locale: locale }),
where filter and locale are local variables
data: JSON.stringify({ jewellerId: filter, locale: locale })
is the best way which I every found, Thank @ChrisCa – Frank Myat Thu Mar 14 '12 at 7:37JSON.stringify
with an object literal, you MUST include the parameter name with a colon, all wrapped inside{}
braces. UsingJSON.stringify(objectLiteral)
doesn't work. – Kaleb Anderson Nov 12 '15 at 22:14[WebMethod] [ScriptMethod(UseHttpGet = true)] public static string TestIBAN(string ccc)
? – Kiquenet Mar 4 '16 at 8:45