When you call the asmx service via jQuery, how to pass arguments?

How to pass the parameters of the service endpoint? (in this case the page will be displayed)

My .asmx service method is as follows:

[WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public List<Object> GetData(int pageSize) { } 

When I call this via jQuery, for example:

 $.ajax({ type: "POST", url: "test.asmx/test123", data: "{}", contentType: "application/json; charset=utf-8", dataType: "json", success: function(msg) { }, error: function(msg) { } }); 
+4
source share
2 answers

You can pass it as json:

 $.ajax({ type: "POST", url: "test.asmx/test123", data: "{'pageSize':'14'}", contentType: "application/json; charset=utf-8", dataType: "json", success: function(msg) { }, error: function(msg) { } }); 
+9
source

You need to create a json object:

 data: {pageSize: 1} 
+2
source

Source: https://habr.com/ru/post/1309358/


All Articles