First of all- I know I should use HTTP POST and I know how to do it.
But my task is to use HTTP GET
anyway. Now, there's a problem. I have a WebMethod
:
[WebMethod]
[ScriptMethod(ResponseFormat=ResponseFormat.Json,UseHttpGet =true)]
public List<string> AddToCollection(string name, string lastname)
{
collection.Add(name + " " + lastname);
return collection;
}
Now, code from .js
:
function AddToArray() {
var name = document.getElementById("name_add").value;
var lastname = document.getElementById("surname_add").value;
if (name == "" || lastname == "") {
alert("Wrong!");
} else {
var dataT = JSON.stringify({"name":name,"lastname":lastname});
$.ajax({
type: "GET",
url: "http://localhost:45250/ServiceJava.asmx/AddToCollection",
data: dataT,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
//something
}
})
}
}
Now the thing is: it works perfect when I use type POST
. But with GET
I get the error that the parameter name
cannot be recognized. What should I change to make it work?