weixin_33716941 2015-01-31 12:45 采纳率: 0%
浏览 4

Ajax URL-错误的.net #c

Been following some tutorials, as i'm learning C#, however was just attempting to make an ajax call to the server, i'm using my localhost.

As far as I can tell i'm doing its right, but it's obviously not. Maybe it my folder structure or just the name of the file.

Folder Structure

The Default.aspx file is at the project root Here is my ajax call

        $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "Default.aspx",
        dataType: "json",
        data: "{'FirstName':'test','LastName':'test1','City':'test3','EmailID':'test4'}",
        success: function (data) {
            console.log("Woo!");
        },
        error: function (result) {
            console.log("fail!");
        }
    });

I know eventually it will have to call a method within the file, but its not even finding it at the moment.

Thanks in advance, James

  • 写回答

1条回答 默认 最新

  • weixin_33736832 2015-01-31 12:56
    关注

    You can use controller Home and create the one action.

    Example:

    public ActionResult FirstAjax()
    {
        return Json(true, JsonRequestBehavior.AllowGet);
    }   
    

    After that your jquery ajax is:

    $.ajax({
            type: "GET",
            contentType: "application/json; charset=utf-8",
            url: "Home/FirstAjax",
            dataType: "json",
            data: "",
            success: function (data) {
                console.log("Woo!");
            },
            error: function (result) {
                console.log("fail!");
            }
        });
    
    评论

报告相同问题?