简体   繁体   English

jQuery自动完成ajax调用ASP.NET时发生内部错误

[英]Internal Error on jQuery Autocomplete ajax call to ASP.NET

For some reason I am getting an Internal Error (500) when I am attempting to get a List of strings from an ASP.NET method. 由于某种原因,当我尝试从ASP.NET方法获取字符串列表时,出现内部错误(500)。 I have tried many different ways of writing it and an entire page of google is all purple but to no avail. 我尝试了许多不同的编写方式,整个Google网页都是紫色的,但无济于事。 Perhaps maybe you guys can spot something I am completely missing. 也许你们可以发现我完全想不到的东西。

Here is the HTML/Javascript 这是HTML / Javascript

<%@ 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>

Here is the WebService code: 这是WebService代码:

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;

        }
    }
}

Here is what the internal error is: 这是内部错误:

在此处输入图片说明

Seems kind of obvious now, but the line 现在似乎有点明显,但是线

// [System.Web.Script.Services.ScriptService]

should be un-commented 应该没有评论

[System.Web.Script.Services.ScriptService]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM