Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/420.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Asp.net Ajax toolkit自动完成扩展器不使用Asp.net C和进度条映像调用web服务_Javascript_C#_Asp.net_Ajaxcontroltoolkit - Fatal编程技术网

Javascript Asp.net Ajax toolkit自动完成扩展器不使用Asp.net C和进度条映像调用web服务

Javascript Asp.net Ajax toolkit自动完成扩展器不使用Asp.net C和进度条映像调用web服务,javascript,c#,asp.net,ajaxcontroltoolkit,Javascript,C#,Asp.net,Ajaxcontroltoolkit,Web服务代码工作正常,但在文本框中无法从数据库获取数据。并且没有显示错误 Web服务代码: /// Summary description for WebService /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] // To allow this Web Service

Web服务代码工作正常,但在文本框中无法从数据库获取数据。并且没有显示错误

Web服务代码:

/// Summary description for WebService

/// </summary>

[WebService(Namespace = "http://tempuri.org/")]

[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

// 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 WebService : System.Web.Services.WebService
  {

  public WebService()
  {


   //Uncomment the following line if using designed components

  //InitializeComponent();

  }


 [WebMethod]

public List<string> GetCountries(string prefixText, int count)

{
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ToString());
    con.Open();
    SqlCommand cmd = new SqlCommand("select * from auto_txt where name like @name+'%'", con);
    cmd.Parameters.AddWithValue("@name", prefixText);
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    DataTable dt = new DataTable();
    da.Fill(dt);
    List<string> ListNames = new List<string>();
    for (int i = 0; i < dt.Rows.Count; i++)
    {
        ListNames.Add(dt.Rows[i][1].ToString());
    }
    con.Close();
    return ListNames;
} }
设计代码Default.aspx:

    <div>

    <asp:ScriptManager ID="ScriptManager1" runat="server"     EnablePartialRendering="false">

    </asp:ScriptManager>

    <asp:TextBox ID="txtCountry" runat="server"  >
   </asp:TextBox>

    <asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="txtCountry" ServiceMethod="GetCountries" ServicePath="~/WebService.asmx" MinimumPrefixLength="2" CompletionInterval="0" EnableCaching="true" CompletionSetCount="20" UseContextKey="True" OnClientPopulating="ShowProcessImage" OnClientPopulated="HideProcessImage" >
    </asp:AutoCompleteExtender>
    </div>
Java脚本代码:

<script type="text/javascript">
    function ShowProcessImage() {
        var autocomplete = document.getElementById('txtCountry');
        autocomplete.style.backgroundImage = 'url(loading1.gif)';
        autocomplete.style.backgroundRepeat = 'no-repeat';
        autocomplete.style.backgroundPosition = 'right';
    }
    function HideProcessImage() {
        var autocomplete = document.getElementById('txtCountry');
        autocomplete.style.backgroundImage = 'none';
    }
</script>

count参数在GetCountries中的用途是什么?如果我删除了count参数,那么也不会从数据库中获取数据;这一行并检查您所在国家/地区名称列的dt值和索引。我建议在for循环中使用columnname而不是像[1]那样的索引。我的意思是使用类似于dt.Rows[I][ColumnName].ToString的东西,而不是dt.Rows[I][1].ToString。我无法使用自动完成扩展器将数据提取到文本框中。如果您有Mozilla,请安装firebug插件。。这是免费的。安装后,在mozilla中运行您的网页。按F12打开Firebug。在其中打开“网络”选项卡。转到所有选项卡。刷新页面。现在在文本框中键入2-3个字符。查看您的Web服务是否被正确获取和调用。检查请求和响应。如果有错误,您可以在控制台选项卡中验证错误。