I have a service contract with a method as follows:
[OperationContract]
[WebInvoke(Method = "POST",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "FibonacciNumber/")]
long FibonacciNumber(long n);
public long FibonacciNumber(long n)
{
var a = 0;
var b = 0;
for(var i = 0; i <= n; i++)
{
if(i == n)
{
return a;
}
var c = a;
a = b;
b = b + c;
}
return 0;
}
However, when I try to call the above with a jquery ajax call, the value of the parameter "n" is 0 when the FibonacciNumber service gets hit, any idea what may be wrong? I did console log the value of "$('#fibIndex').val()" and it shows the correct value on the client:
$('#btnFib').on('click', function () {
fibIndex = $('#fibIndex').val();
$.ajax({
url: "http://localhost:61924/MyService.svc/FibonacciNumber/",
type: "POST",
dataType: "json",
data: Number(fibIndex),
}).done(function (data) {
$('#fibResult').html(data);
}).fail(function () {
console.log("error");
});
});
Thank you in advance for shedding some light in this regards.