Javascript asp.net c#4.5对WebMethod的调用不会返回任何内容
我有一个简单的WebMethod调用,它不返回任何内容。我没有收到任何错误 代码非常简单。我只是想知道是否有一个设置(IIS、webconfig等)不正确。我有VS Pro 2013、Framework=4.5和IIS 10.0 Express 有没有想过为什么我的“Hello World!”程序不起作用 JavaScript.aspx.csJavascript asp.net c#4.5对WebMethod的调用不会返回任何内容,javascript,c#,jquery,asp.net,Javascript,C#,Jquery,Asp.net,我有一个简单的WebMethod调用,它不返回任何内容。我没有收到任何错误 代码非常简单。我只是想知道是否有一个设置(IIS、webconfig等)不正确。我有VS Pro 2013、Framework=4.5和IIS 10.0 Express 有没有想过为什么我的“Hello World!”程序不起作用 JavaScript.aspx.cs using System; using System.Collections.Generic; using System.Linq; using Syst
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
namespace WebApplication1
{
public partial class JavaScript : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod]
public static string GetData()
{
return "Hello World!";
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="JavaScript.aspx.cs" Inherits="WebApplication1.JavaScript" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$(document).ready(function () {
$.ajax({
type: "POST",
url: "JavaScript.aspx/GetData",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
$("#Content").text(response.d);
},
failure: function (response) {
alert(response.d);
}
});
});
</script>
</head>
<body>
<form id="frm" method="post">
<div id="Content">
</div>
</form>
</body>
</html>
JavaScript.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
namespace WebApplication1
{
public partial class JavaScript : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod]
public static string GetData()
{
return "Hello World!";
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="JavaScript.aspx.cs" Inherits="WebApplication1.JavaScript" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$(document).ready(function () {
$.ajax({
type: "POST",
url: "JavaScript.aspx/GetData",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
$("#Content").text(response.d);
},
failure: function (response) {
alert(response.d);
}
});
});
</script>
</head>
<body>
<form id="frm" method="post">
<div id="Content">
</div>
</form>
</body>
</html>
$(文档).ready(函数(){
$.ajax({
类型:“POST”,
url:“JavaScript.aspx/GetData”,
contentType:“应用程序/json;字符集=utf-8”,
数据类型:“json”,
成功:功能(响应){
$(“#内容”).text(response.d);
},
故障:功能(响应){
警报(response.d);
}
});
});
由于我无法发布图像(声誉点数不足),请单击此链接查看我的网络选项卡:
为什么要发帖子,请将其更改为get I hope that workWatch,使用浏览器的调试工具查看网络请求。响应的状态代码是什么?响应内容是什么样子的?webmethod是否通过调试模式工作?我还可以推荐Postman来测试web服务和调试类似的错误,这对于确定问题是服务器还是客户端非常有帮助。您也可以尝试将“Hello World!”格式化为JSON。我已经测试了您的代码,它似乎工作得很好,根据您的网络选项卡,AJAX调用似乎成功。也许您可以在网络选项卡中共享GetData调用响应的内容?