【问题标题】:jquery ajax not working when I using asp.net routing with asp.net webforms当我将 asp.net 路由与 asp.net webforms 一起使用时,jquery ajax 不起作用
【发布时间】:2017-06-01 03:56:30
【问题描述】:

我在我的项目中使用 asp.net 路由和 asp.net webforms 但我的 jquery ajax 方法不起作用 我如何解决这个问题

我的服务器端方法是:

[WebMethod]
public static string search(List<string> aData)
{
       //my code
       return "resault";
}

我的客户端功能是:

function search(e) {

    if (e.value == "") {
        //$("#imgLoading").hide();
        $("#search-res").html("");
        $("#search-res").slideUp();
        return;
    }
    else {
        $("#search-res").html("<img src='/content/img/loading (4).gif' alt='Alternate Text' />");


    }
    var aData = [];
    aData[0] = e.value;
    var jsonData = JSON.stringify({ aData: aData });



    $.ajax({
        type: "POST",
        url: '/User/default.aspx/search',
        data: jsonData,
        contentType: "application/json; charset=utf-8",
        dataType: "json",

        success: function (res) {

            var items = res.d;

            $("#search-res").html(res.d);
            $("#search-res").slideDown();


        },
        error: function (type) {
            alert(type.responseText);
        }
    });
}

在我使用路由之前,我的 jquery 函数工作正常

【问题讨论】:

  • alert which is inside error.,这叫什么??您是否收到任何失败通知?
  • HTTP 错误 404.0 - 未找到您要查找的资源已被删除、更改名称或暂时不可用。
  • 是的,我收到 http 错误 404
  • 你能发布你的 .aspx 代码吗?
  • 否,因为它找不到我要发布的网址

标签: jquery asp.net ajax webforms routing


【解决方案1】:

好的,我的问题解决了

我改变了我的代码

function search(e) {

    if (e.value == "") {
        //$("#imgLoading").hide();
        $("#search-res").html("");
        $("#search-res").slideUp();
        return;
    }
    else {
        $("#search-res").html("<img src='/content/img/loading (4).gif' alt='Alternate Text' />");


    }
    var aData = [];
    aData[0] = e.value;
    var jsonData = JSON.stringify({ aData: aData });


    var Url='/User/Default.aspx/search'
    $.ajax({
        type: "POST",
        url: Url,
        data: jsonData,
        contentType: "application/json; charset=utf-8",
        dataType: "json",

        success: function (res) {

            var items = res.d;

            $("#search-res").html(res.d);
            $("#search-res").slideDown();


        },
        error: function (type) {
            alert(type.responseText);
        }
    });
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多