我一直没有找到任何解决此问题的好方法,所以我需要som帮助。asp.net pagemethod调用,使用jquery,返回错误状态500
我有一个PageMethod,我需要调用jQuery。客户端代码如下所示:
<script type="text/javascript">
$(function() {
$("#MainContent_ddl_antal").change(function() {
var selectedvalue = $(this).val();
//alert(selectedvalue);
$.ajax({
type: "POST",
url: "betaling.aspx/GetTotPrice",
data: "{'antal':" + selectedvalue + "}",
//data: JSON.stringify({ antal: selectedvalue }),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
// Set label text to method's return.
alert(msg.d);
$('#<%= lbl_totpris.ClientID %>').html(msg.d);
},
error: function (error) {
alert(error.status);
}
});
});
});
</script>
和代码隐藏PageMethod的是这样的:
[WebMethod]
public static double GetTotPrice(int antal)
{
double totpris = 0;
Product _product = Product.GetProductByDate(DateTime.Today);
if (_product != null)
{
totpris = _product.ProductNuPris * antal;
}
return totpris;
}
调用返回一个错误500。我看不到这样做的原因。
您是否能够在调试器中运行您的webmethod以确保它正在调用并返回值? – Geoff 2011-03-16 10:58:27
你有试过调试吗?也许传给'antal'的值不是整数。 – TheVillageIdiot 2011-03-16 10:59:52