更新时间:2022-05-23 08:53:39
.ajax({
url:'../ITS/Reports.aspx/GetReport',
方法:'post',
contentType:'application / json; charset = utf-8',
data:{ID:ID},>
dataType:'json',
async:true,
cache:false,
success:function(data){
}
});
}
------------- ----------
关于C#Reports.aspx.cs
----------------- -----
[System.Web.Services.WebMethod]
public bool GetReport(int ID)
{
Globel gbl = new Globel();
DataTable Dt = gbl.GetData(ID);
返回true;
}
请帮我解答代码中的错误。
谢谢......
我尝试过:
尝试使用ajax在asp.net网页上调用WebMethod 。
.ajax({
url: '../ITS/Reports.aspx/GetReport',
method: 'post',
contentType: 'application/json; charset=utf-8',
data: {ID: ID},
dataType: 'json',
async: true,
cache: false,
success: function (data) {
}
});
}
-----------------------
On C# Reports.aspx.cs
----------------------
[System.Web.Services.WebMethod]
public bool GetReport(int ID)
{
Globel gbl = new Globel();
DataTable Dt = gbl.GetData(ID);
return true;
}
Please help me what is the mistake in my code.
Thank You...
What I have tried:
Trying to call WebMethod on asp.net web page using ajax.
参考此代码,查看内联评论
refer this code, check the inline comments
[System.Web.Services.WebMethod]
public static bool GetReport(int ID) // make it as static
{
// Your code
return true;
}
function GetData(id) {
var ID = parseInt(id); // make sure you are passing the integer value
var obj = { ID: ID };
var param = JSON.stringify(obj); // stringify the parameter
.ajax({
url:'/ITS / _Reports.aspx / GetReport',//删除..
方法:' post',
contentType:'application / json; charset = utf-8',
data:param,
dataType:'json',
async:true,
cache:false,
success:function(data){
alert(data.d); // true
},
error:function(xhr,status,error) {
alert(xhr.responseText); //查看错误消息
}
});
}
GetData(1);
.ajax({ url: '/ITS/Reports.aspx/GetReport', // remove the .. method: 'post', contentType: 'application/json; charset=utf-8', data: param, dataType: 'json', async: true, cache: false, success: function (data) { alert(data.d); // true }, error: function (xhr, status, error) { alert(xhr.responseText); // to see the error message } }); } GetData(1);