我试图使用ajax在ASP.NET网页上调用webmethod。发生500内部服务器错误。 [英] I am trying to call webmethod on ASP.NET web page using ajax. Occurring 500 internal server error.

查看:113
本文介绍了我试图使用ajax在ASP.NET网页上调用webmethod。发生500内部服务器错误。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的先生/妈妈,



我正在尝试使用ajax在asp.net网页上调用WebMethod。发生500内部服务器错误和方法没有调用。

我的代码是:

-------------

在ASPX页面上

-------------



函数GetData(ID){

$ .ajax({

url:'../ITS/Reports.aspx/GetReport',

方法:'post',

contentType:'application / json; charset = utf-8',

data:{ID:ID},

dataType:'json',

async:true,

cache:false,

成功:函数(数据){

}

});

}

-----------------------

关于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 。

Dear Sir/Mam,

I am trying to call WebMethod on asp.net web page using ajax. occurring 500 Internal server error and method is not calling.
My Code is :
-------------
On ASPX Page
-------------

function GetData(ID) {
$.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.

推荐答案

.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);


这篇关于我试图使用ajax在ASP.NET网页上调用webmethod。发生500内部服务器错误。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆