C# jQuery自动完成对ASP.NET的ajax调用时出现内部错误
由于某种原因,当我试图从ASP.NET方法获取字符串列表时,我收到一个内部错误(500)。我尝试过许多不同的写作方式,整个谷歌页面都是紫色的,但都没有用。也许你们能发现我完全丢失的东西 下面是HTML/JavascriptC# jQuery自动完成对ASP.NET的ajax调用时出现内部错误,c#,jquery,asp.net,ajax,C#,Jquery,Asp.net,Ajax,由于某种原因,当我试图从ASP.NET方法获取字符串列表时,我收到一个内部错误(500)。我尝试过许多不同的写作方式,整个谷歌页面都是紫色的,但都没有用。也许你们能发现我完全丢失的东西 下面是HTML/Javascript <%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="messaging.aspx.cs" Inherits="xxx.mes
<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="messaging.aspx.cs" Inherits="xxx.messaging" %>
<asp:Content ID="Content1" ContentPlaceHolderID="content" runat="server">
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script type="text/javascript">
$(document).ready(function () {
//$(".selectable").selectable();
$('[id$="username_textbox"]').autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Services.asmx/getFollowingUsernames",
dataFilter: function (data) { return data; },
data: "{'prefixText': '" + request.term + "' }",
dataType: "json",
success: function (data) {
response(data.d);
},
error: function (xhr, textStatus, errorThrown) {
var errorMessage = "Ajax error: " + this.url + " : " + textStatus + " : " + errorThrown + " : " + xhr.statusText + " : " + xhr.status;
if (xhr.status != "0" || errorThrown != "abort") {
alert(errorMessage);
}
}
});
},
search: function (event, ui) {
$('.spinner').show();
},
response: function (event, ui) {
$('.spinner').hide();
},
minLength: 1
});
});
</script>
<div class="messaging_wrapper">
<div class="conversations_list" runat="server">
<asp:Button ID="new_message" runat="server" Text="New Message" />
<ol id="conversation_ol" class="selectable" runat="server">
</ol>
</div>
<div id="conversation_wrapper" class="converation_div" runat="server">
<div id="conversation_head">
<asp:TextBox ID="username_textbox" runat="server"></asp:TextBox>
<img src="images/ajax-loader.gif" style="display:none" class="spinner" />
</div>
</div>
</div>
</asp:Content>
$(文档).ready(函数(){
//$(“.selective”).selective();
$('[id$=“用户名\文本框”]')。自动完成({
来源:功能(请求、响应){
$.ajax({
类型:“POST”,
contentType:“应用程序/json;字符集=utf-8”,
url:“Services.asmx/getfollowerusernames”,
dataFilter:函数(数据){返回数据;},
数据:“{'prefixText':'”+request.term+“}”,
数据类型:“json”,
成功:功能(数据){
答复(数据d);
},
错误:函数(xhr、textStatus、errorshown){
var errorMessage=“Ajax error:“+this.url+”:“+textStatus+”:“+errorshown+”:“+xhr.statusText+”:“+xhr.status;
if(xhr.status!=“0”| | errorhorn!=“中止”){
警报(错误消息);
}
}
});
},
搜索:功能(事件、用户界面){
$('.spinner').show();
},
响应:功能(事件、用户界面){
$('.spinner').hide();
},
最小长度:1
});
});
以下是Web服务代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace xx.App_Code
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class Services : System.Web.Services.WebService
{
[WebMethod]
public List<string> getFollowingUsernames(string prefixText)
{
SessionAdapter sa = new SessionAdapter();
int id = sa.getUserID();
MembershipAdapter ma = new MembershipAdapter();
List<int> ids = new List<int>();
ids = ma.getUserFollowingList(id);
List<string> usernames = new List<string>();
foreach (int userID in ids)
{
usernames.Add(ma.getUserName(userID.ToString()));
}
return usernames;
}
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Web;
使用System.Web.Services;
名称空间xx.App_代码
{
[WebService(命名空间=”http://tempuri.org/")]
[WebServiceBinding(ConformsTo=WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
//要允许使用ASP.NET AJAX从脚本调用此Web服务,请取消注释以下行。
//[System.Web.Script.Services.ScriptService]
公共类服务:System.Web.Services.WebService
{
[网络方法]
公共列表GetFollower用户名(字符串前缀)
{
SessionAdapter sa=新SessionAdapter();
int id=sa.getUserID();
MembershipAdapter ma=新的MembershipAdapter();
列表ID=新列表();
ids=ma.GetUserFollowList(id);
列表用户名=新列表();
foreach(id中的int userID)
{
usernames.Add(ma.getUserName(userID.ToString());
}
返回用户名;
}
}
}
以下是内部错误:
现在似乎有点明显,但界线
// [System.Web.Script.Services.ScriptService]
应该不予评论
[System.Web.Script.Services.ScriptService]