I want to get value of currency from codebehind that then I call it using ajax, but I got nothing, it just show error, here the code
function js
function showCRate2(obj) {
var selectedCurrency = $('#<%=ddlPaymentCurrency.ClientID%>').val();
console.log(selectedCurrency);
if (selectedCurrency != null && selectedCurrency != "") {
$.ajax({
type: "POST",
url: "TopUp.aspx/GetCRate",
data: '{id:"' + selectedCurrency + '"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
var o = response.d;
$('#<%=hfCurrencyRate.ClientID%>').val(o.RateBuy);
$('#<%=hfCR.ClientID%>').val(o.RateBuy);
},
error: function (response) {
alert('error')
}
});
}
}
and this the function in codebehind, return object(that later I need the value of it's RateBuy attribut (decimal)
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static OLServiceReference.CurrRate getCurr(int id)
{
var CR = client.GetCurrRates(id);
return CR;
}
and these another related control
<asp:DropDownList ID="ddlPaymentCurrency" CssClass="form-control" runat="server" onChange="showCRate2()"></asp:DropDownList>
<input type="text" id="hfCurrencyRate" runat="server" class="form-control" placeholder="" style="width: 230px" readonly="readonly" />
<asp:HiddenField ID="hfCR" runat="server" /></div>
on calling showCRate2(obj) just error alert occured (error: function(response)) .I expect that form hfCurrencyRate show the Currency of Buy Rates. How to fix this? Any Idea?