自己写的 “UseHttpGet = false” 而你的js又用GET方式去访问.
解决方案 »
- 什么软件能代替VS2008啊?总喜欢假死,无法输入或者保存,或者退格
- ORA-01036: 非法的变量名/编号
- 如何访问自定义控件里面的方法
- Dns解析
- 请高人帮忙解释一下如何安装配置服务器群集Microsoft Cluster Service (MSCS)
- ajax总是返回null值,在线等,谢谢.
- Visual Studio 2003 问题:试图开始编译时出现错误
- 唉,ASP.NET初体验失败,前辈们指点一下吧
- 怎么样自己创建控件!?并且让它可以加入项目成为可使用控件!小弟菜鸟,请大哥们指教!
- 关于一个页面上用两个不同的自定义验证控件来验证两组文本框!!!
- 如何以数组的元素作为索引获取到该行数组的数据
- Easyui中使用datagrid做类似于Excel的条件筛选
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Script.Services;
using System.Web.Script.Serialization;namespace MeierbeiWebDtService
{
/// <summary>
/// WebService 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService
{
[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public string HelloWorld()
{
JavaScriptSerializer js = new JavaScriptSerializer();
Context.Response.Clear();
Context.Response.ContentType = "application/json";
Models.HelloWorldData data = new Models.HelloWorldData();
data.Message = "HelloWorld";
data.Name = "MicJackson";
return js.Serialize(data);
} [WebMethod]
[ScriptMethod(UseHttpGet = false, ResponseFormat = ResponseFormat.Json)]
public void GetClass(int fenshu)
{
JavaScriptSerializer js = new JavaScriptSerializer();
Context.Response.Clear();
Context.Response.ContentType = "application/json";
Models.HelloWorldData data = new Models.HelloWorldData();
if (fenshu > 90)
{
data.Message = "优异";
data.Name = "语文";
}
else if (fenshu > 80)
{
data.Message = "良好";
data.Name = "语文";
}
else if (fenshu > 60)
{
data.Message = "及格";
data.Name = "语文";
}
else
{
data.Message = "不及格";
data.Name = "语文";
}
HttpRequest Request = HttpContext.Current.Request;
string callback = Request["jsonp"];
Context.Response.Write(callback + "(" + js.Serialize(data) + ")");
Context.Response.End();
//return js.Serialize(data);
}
}
}
<html>
<head>
<script src="jquery-1.11.1.min.js" type="text/javascript"></script>
</head>
<body>
<script type="text/javascript">
function callbackjsp(result){
alert("Message:"+result.Message + ",Name:"+result.Name);
}
$(document).ready(function(){
$.ajax({
url: "http://localhost:53568/WebService.asmx/GetClass",
type: "GET",
dataType: "jsonp",
jsonp: "jsonp", //传递给请求处理程序或页面的,用以获得jsonp回调函数名的参数名(默认为:callback)
jsonpCallback: "callbackjsp", //自定义的jsonp回调函数名称,默认为jQuery自动生成的随机函数名
data: { fenshu: 93 },
success: function (json) {
alert("success:" + json.Message);
},
error: function (x, e) {
//alert("error:" + x.responseText);
},
complete: function (x) {
//alert("complete:" + x.responseText);
}
});
});
</script>
</body>
</html>