[英]Ajax call is not invoking server side method
$(document).on('click', '#year', function(event) {
event.preventDefault();
var startDate = new Date();
alert(startDate);
plotGraph('year',startDate);
});
function plotGraph(detail,dt) {
alert(detail+" "+dt);
$.ajax({
type: "POST",
url: "BillnAmount",
data: {detail: detail,dt:dt},
cache: false,
dataType: 'json',
success: function(data) {
console.log(data);
alert('succe');
}
error: function(data) {
alert("not able to fetch data");
}
});
}
我正在使用上述程序来调用服务器端语言以下的代码上面的代码正在正确执行,并且显示成功警报消息,但未在执行服务器方法plotBillnAmount()
public String plotBillnAmount() {
System.out.println("plotBillnAmount() ");
System.out.println("detail " + getDetail() + " dt " + getDt());
}
可能是什么问题?
您需要使用[webmethod]标签和url页面将您的方法标记为静态。aspx/ methodname
jQuery的
$.ajax({
type: "POST",
url: "WebForm1.aspx/showMsg",
contentType: "application/json;charset=utf-8",
dataType: 'json',
success: function (data) {
alert(data.d);
},
error: function (data) {
alert("not able to fetch data");
}
});
C#
[WebMethod]
public static string showMsg()
{
return "Hello world";
}
你好试试这个。
<script type="text/javascript">
$(document).ready(function() {
$.getJSON("http://", function(data) {
$.each(data.categories, function(index, item) {
categoriesId.push(item.productName);
}
);
for (i = 0; i < categoriesId.length; i++) {
alert(categoriesId[i]);
}
}
);
}
);
</script>
如果您收到来自Web服务的警报,请告诉我,您遇到一些问题,然后将您的Web服务发送给我,我将以方便的格式显示数据。
您必须像这样格式化数据字段:
data: '{"detail":"' + detail + '", dt":"' +dt'"}',
另外,您的url字段应说明哪个文件包含您的方法:
url: "file.aspx/BillnAmount",
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.