jQuery的AJAX错误,而使用C#功能 [英] jquery ajax error while using c# function
本文介绍了jQuery的AJAX错误,而使用C#功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用jQuery AJAX在我的项目。我只是运行一个简单的Ajax和code后面。我得到了警告错误,因为500内部错误
<脚本类型=文/ JavaScript的SRC =jQuery的-1.2.6.min.js>< / SCRIPT>
<脚本类型=文/ JavaScript的>
$(文件)。就绪(函数(){
$阿贾克斯({
键入:POST,
网址:listprac.aspx / sayHello的,
的contentType:应用/ JSON的;字符集= UTF-8,
数据: {},
数据类型:JSON,
成功:AjaxSucceeded,
错误:AjaxFailed
});
});
功能AjaxSucceeded(结果){
警报(result.d);
}
功能AjaxFailed(结果){
警报(result.status +''+ result.statusText);
}
< / SCRIPT>
我的$ C $落后C:
公共静态字符串的sayHello()
{
返回你好;
}
解决方案
有关 ASPX
页面,你就必须有装饰你的code隐藏方法 [WebMethod的()]
属性:
[WebMethod的()
公共静态字符串的sayHello()
{
返回你好;
}
编辑: 的WebMethod
是 System.Web.Services.WebService
命名空间内
I want to use jquery ajax in my project. I just run a simple ajax with code behind. I got the alert error as "500 internal error"
<script type="text/javascript" src="jquery-1.2.6.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$.ajax({
type: "POST",
url: "listprac.aspx/sayHello",
contentType: "application/json; charset=utf-8",
data: "{}",
dataType: "json",
success: AjaxSucceeded,
error: AjaxFailed
});
});
function AjaxSucceeded(result) {
alert(result.d);
}
function AjaxFailed(result) {
alert(result.status + ' ' + result.statusText);
}
</script>
My code behind:
public static string sayHello()
{
return "hello ";
}
解决方案
For aspx
pages you'll have to decorate your code-behind method with the [WebMethod()]
attribute:
[WebMethod()]
public static string sayHello()
{
return "hello ";
}
Edit: WebMethod
is within the System.Web.Services.WebService
namespace.
这篇关于jQuery的AJAX错误,而使用C#功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文