asp.net - jquery ajax call to WCF service passing data with a data type "long" value sends 0 -


i have service contract method 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 = 0;         var b = 0;          for(var = 0; <= n; i++)         {             if(i == n)             {                 return a;             }              var c = a;             = b;             b = b + c;         }          return 0;     } 

however, when try call above jquery ajax call, value of parameter "n" 0 when fibonaccinumber service gets hit, idea may wrong? did console log value of "$('#fibindex').val()" , shows correct value on 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 in advance shedding light in regards.

i found issue code. problem was missing contenttype , not passing correct data. correct example follows:

$('#btnfib').on('click', function () {         var fibindex = number($('#fibindex').val());          $.ajax({             url: "http://localhost:61924/myservice.svc/fibonaccinumber/",             type: "post",             datatype: "json",             contenttype: "application/json",             data: json.stringify(fibindex),         }).done(function (data) {             $('#fibresult').html(data);         }).fail(function (a) {             console.log(a);         });     }); 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -