使用asmx的Ajax POST 404错误

时间:2015-10-21 19:29:49

标签: javascript c# jquery ajax web-services

我正在尝试创建一个可以从javascript代码调用/ POST的web方法,但是每当调用test()函数时,我都会在控制台中获得以下错误:

“POST http://localhost:53093/TestMethods.asmx/HelloWorld 404(未找到)”

我检查过与我类似的多个问题,但没有一个解决方案似乎有效。任何帮助将不胜感激。

TestMethods.asmx.cs

[WebService(Namespace = "http://testdomain.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[ScriptService]
public class TestMethods : System.Web.Services.WebService
{

    [WebMethod()]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public static string HelloWorld()
    {
        return "Hello World";
    }
}

Javascript (game.js)

function test()
{
    $.ajax({
        url: "TestMethods.asmx/HelloWorld",
        type: 'POST',
        data: "{}",
        dataType: 'json',
       contentType: 'application/json; charset=utf-8',
        success: function (result) {
            alert(result);
        }
    });
}

File Structure Image

0 个答案:

没有答案