As a newcomer to web development, I decided to create an ASP.NET project with a web API to test my skills. In the process, I crafted a controller and some JavaScript files as follows:
Controller:
namespace MyNamespace.Controllers
{
public class PairController : ApiController
{
public Point Get([FromUri]int rows, [FromUri]int cols)
{
return new Point(rows, cols);
}
}
}
JS:
var api = 'api/Pair';
var question = '/?rows=' + $('#rows').val() + '&cols=' + $('#cols').val();
var url = api + question;
$.getJSON(url, function (data) {
alert('success');
console.log(data[0].X + ' ' + data[0].Y);
}).fail(function () {
alert('error!');
});
Upon checking the console, I noticed two 'undefined' lines instead of the expected values from the input fields for rows and cols.
I presumed that the server would serialize the point into JSON format and send back the answer:
{
"X": value from rows input,
"Y": value from cols input,
"IsEmpty": something
}