이 문제에 대한 좋은 해결책을 찾을 수 없어서 som help가 필요합니다.asp.net pagemethod 호출, jquery를 사용하여 오류 상태를 반환합니다. 500
jquery로 호출해야하는 PageMethod가 있습니다.
<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
디버깅을 시도하셨습니까? 어쩌면'antal'의 전달 된 값은 정수가 아닙니다. – TheVillageIdiot