【发布时间】:2015-11-06 13:35:42
【问题描述】:
我想从代码隐藏中获取货币的价值,然后我使用 ajax 调用它,但我什么也没得到,它只是显示错误,这里是代码
函数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')
}
});
}
}
这是代码隐藏中的函数,返回对象(稍后我需要它的 RateBuy 属性值(十进制)
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static OLServiceReference.CurrRate getCurr(int id)
{
var CR = client.GetCurrRates(id);
return CR;
}
还有这些其他相关的控件
<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>
在调用 showCRate2(obj) 时发生错误警报(错误:函数(响应))。我希望表单 hfCurrencyRate 显示买入汇率的货币。如何解决这个问题?有什么想法吗?
【问题讨论】:
-
检查浏览器的控制台窗口,看看它显示了什么错误信息。
标签: javascript c# jquery asp.net ajax