jquery - ASP.net WebMethod 返回完整的页面内容而不是 JSON 数据

标签 jquery asp.net .net ajax json

我正在尝试文本框的自动完成功能,其中我向 webmethod 发送 get 请求,该 webmethod 返回完整的页面内容而不是实际数据,如下所示。

enter image description here

我正在使用以下 C# 代码,而我使用 Post 请求的所有其他方法都工作正常

[WebMethod]
        [ScriptMethod(UseHttpGet=true,ResponseFormat=ResponseFormat.Json)]
        public static string GetListOfUsers()
        {
            return "{'0701414001','0701414002'}";
        }

最佳答案

我认为问题出在您的参数中:您正在调用 Email.aspx/GetListOfUusers?query=lkkjlk 但您的 public static string GetListOfUsers() 不包含参数名称。

尝试更改为:

public static string GetListOfUsers(string query)
{
...
}

我还会尝试删除此内容:ResponseFormat=ResponseFormat.Json 并查看它是否会改变任何内容。

关于jquery - ASP.net WebMethod 返回完整的页面内容而不是 JSON 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10776113/

相关文章:

javascript - json 对象到 javascript 全局引用

javascript - 从子字符串中删除单词

C#,如何获取网页内容?

c# - 用 C# 读取 OLE 对象

c# - 如何在运行时确定 C# 中 WPF 控件的边界?

c# - 跟踪多个 BackgroundWorker

jQuery.error() 不适用于 iframe。

asp.net - 编译器错误消息: CS0433: The type 'System.Web.Helpers.Json' exists in both

asp.net - 无法加载文件或程序集 'Microsoft.Threading.Tasks.Extensions.Desktop' 或其依赖项之一。参数不正确

javascript - 如何使我的 CSS 更新一致?