我有一个简单的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 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!";
}
}
}
JavaScript.aspx.cs
<%@ 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>
由于我无法发布图片(信誉点不够),请点击此链接查看我的网络标签: Here is the Network Tab