本文介绍了从数据库中获取的话并传递给在浏览器中运行一个脚本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

    <body>

            <h3 id="apply-to-multiple-textareas">Apply to Multiple Textareas</h3>
            <div class="textarea-wrapper">
                <textarea class="textarea4 form-control" rows="4"></textarea>
            </div>
            <div class="textarea-wrapper">
                <textarea class="textarea4 form-control" rows="4"></textarea>
            </div>



            </body>            

<script type="text/javascript" class="brush: js; script" >

            $('.textarea').textcomplete([
                { // tech companies
                    words: [],
    <%
    Class.forName("com.mysql.jdbc.Driver");
    Connection con4=DriverManager.getConnection("jdbc:mysql://localhost:3306/hospital","root","root");
    String vsql4 ;
    try
    {
        Statement st4=con4.createStatement();
        vsql4="select hi from new1";
        ResultSet Rs4=st4.executeQuery(vsql4);
        while(Rs4.next())
        {
            %>
            words.push("<%= Rs4.getString("hi") %>");
            <%
        }
        %>

                    match: /\b(\w{2,})$/,
                    search: function (term, callback) {
                        callback($.map(this.words, function (word) {
                            return word.indexOf(term) === 0 ? word : null;
                        }));
                    },
                    index: 1,
                    replace: function (word) {
                        return word + ' ';
                    }
                }
            ]);
            </script>

我试过,但没有得到结果是什么错在这里我是新的JavaScript我打算autocomplate我的textarea它的工作原理上的话: ['苹果','谷歌','Facebook的, GitHub的'] ,但当我从数据库没有得到结果检索

I tried this but not getting result is something wrong here i am new in javascript i am going to autocomplate my textarea it works on words: ['apple', 'google', 'facebook', 'github'], but when I retrieve it from db not getting result

推荐答案

勾选此,它可以帮助你。

Check this, it may help you

<head id="Head1" runat="server">
<title></title>
<link href="Styles/jquery-ui.css" rel="stylesheet" type="text/css" />
<script src="Scripts/jquery-1.9.1.js" type="text/javascript"></script>
<script src="Scripts/jquery-ui.js" type="text/javascript"></script>
<script type="text/javascript">
           $(document).ready(function () {
$("#txtSearch").autocomplete({
    source: function (request, response) {
        $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: "WebService.asmx/GetData",
            data: "{'DName':'" + document.getElementById('txtSearch').value + "'}",
            dataType: "json",
            success: function (data) {
                response(data.d);
            },
            error: function (result) {
                alert("Error......");
            }
        });
    }
});
});
 </script>
</head>

public class WebService : System.Web.Services.WebService
{
[WebMethod]
public List<string> GetData(string DName)
{
    List<string> result = new List<string>();
    using (SqlConnection con = new SqlConnection("Data Source=SYSTEM-30;database=DB_Test_Trainees;user id=test;password=Test"))
    {
        using (SqlCommand cmd = new SqlCommand("select Dname from DEPTDHII where Dname like '%'+@SearchText+'%'", con))
        {
            con.Open();
            cmd.Parameters.AddWithValue("@SearchText", DName);
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                result.Add(dr["DName"].ToString());
            }
            return result;
        }
      }
   }

}

对此现场一看 - > http://www.c-sharpcorner.com/UploadFile/29d7e0/jquery-autocomplete-getting-data-from-database-in-Asp-Net/

have a look on this site -> http://www.c-sharpcorner.com/UploadFile/29d7e0/jquery-autocomplete-getting-data-from-database-in-Asp-Net/

这篇关于从数据库中获取的话并传递给在浏览器中运行一个脚本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 16:59