weixin_33693070 2015-10-21 19:29 采纳率: 0%
浏览 37

AMX的Ajax POST 404错误

I am attempting to create a webmethod that I can call/POST to from javascript code, but I obtain the following error in console whenever the test() function is called:

"POST http://localhost:53093/TestMethods.asmx/HelloWorld 404 (Not Found)"

I have checked multiple questions similar to mine, but none of the solutions seem to work. Any help would be appreciated.

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条回答 默认 最新

    报告相同问题?