I'm trying to send some data with an Ajax Post request. The code of the request is the following:
$.ajax({
url: "[url of page]",
type: "POST",
data: {saluto: true},
dataType: 'text',
success: function (response) {
alert("successful" + response);
},
error: function () {
alert("error");
}
});
So in this case I should receive saluto = true
This is the Backend code:
[HttpPost("Test")]
public async Task<string> testHelloWorld(bool saluto)
{
try
{
string testString = "Funziona";
Console.Write(testString + ": " + saluto + "\n");
return testString;
}
catch (Exception ex)
{
Log.Error("API(CallToXML) - Exception", ex);
return null;
}
}
So if saluto = true
My console should print "Funziona: True"
the OUTPUT tho is "Funziona: False"
If I try the same thing with a string, it won't print the string and just leaves the output like "Funziona: "
Why isn't my code reciving any data? Is there anything I'm doing wrong? Thanks.