Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/300.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
C# jQuery自动完成,调用函数时出现问题_C#_Javascript_Jquery_Asp.net_Webforms - Fatal编程技术网

C# jQuery自动完成,调用函数时出现问题

C# jQuery自动完成,调用函数时出现问题,c#,javascript,jquery,asp.net,webforms,C#,Javascript,Jquery,Asp.net,Webforms,我在一个屏幕上运行jQuery autocomplete,该屏幕调用函数从另一个.aspx页面获取数据。安装程序在本地运行时工作正常,但当我在主机上运行时,出现了一个错误,这是我在安装程序不工作时收到的消息。唯一的问题是,我不明白为什么它可以在本地工作,但在本地主机上托管时却不能工作 带有自动完成框的ASPX页面: $(document).ready(function () { document.getElementById('<%=txtCustomerType.ClientID

我在一个屏幕上运行jQuery autocomplete,该屏幕调用函数从另一个.aspx页面获取数据。安装程序在本地运行时工作正常,但当我在主机上运行时,出现了一个错误,这是我在安装程序不工作时收到的消息。唯一的问题是,我不明白为什么它可以在本地工作,但在本地主机上托管时却不能工作

带有自动完成框的ASPX页面:

$(document).ready(function () {
    document.getElementById('<%=txtCustomerType.ClientID %>').onclick = SearchText();
});

    function SearchText() {
        $(".autosuggest").autocomplete({
            source: function (request, response) {
                $.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    url: "/../JQueryAutoComplete.aspx/GetAutoCompleteData",
                    data: "{'Customer':'" + document.getElementById(
                        '<%=txtCustomerType.ClientID %>').value + "'}",
                dataType: "json",
                success: function (data) {
                    response(data.d);
                },
                error: function (result) {
                    alert('An error occurred!');
                }
            });
        }
    });

    $(".autosuggest").autocomplete({
        select: function (a, b) {
            checkDirty = false;
            $(this).val(b.item.value);
            $("form").submit()
        }
    });
它调用的Jquery页面后面的代码:

public partial class _Default : System.Web.UI.Page {

    protected void Page_Load(object sender, EventArgs e) {

    }
    [WebMethod]


    public static List<string> GetAutoCompleteData(string Customer) {
        List<string> result = new List<string>();

        SqlConnection dbConnection = new SqlConnection(GetConnection.GetConnectionString());

        using (SqlConnection con = dbConnection) {
            DataSet ds = new DataSet();
            using (SqlCommand cmd = new SqlCommand(
                    "PL_CustomerTypes_IntelliSearch", dbConnection)) {

                cmd.Parameters.Add("@SearchText", SqlDbType.NVarChar).Value = Customer;
                cmd.CommandType = CommandType.StoredProcedure;

                SqlDataAdapter da = new SqlDataAdapter();
                da.SelectCommand = cmd;

                da.Fill(ds);

                DataTable dtResults = new DataTable();
                dtResults = ds.Tables[0];

                foreach (DataRow R in dtResults.Rows) {
                    string strResult = (string)R.ItemArray[0];
                    result.Add(strResult);
                }


                //while (dr.Read()) {
                //    string Name = (dr["ACNT_NAME"].ToString().Trim());
                //    result.Add(Name);
                //}

                return result;

            }
        }
    }

}

检查URL:/../JQueryAutoComplete.aspx/GetAutoCompleteData。重写它而不诉诸../

另外,为了确保可以从错误函数中获得更多信息,请参见,其签名为 functionjQxhr、textStatus、errorThrown[而不是functionresult],将其用作错误处理程序,以便检查它是否由于404或其他原因而失败:

function(xhr){
  alert(xhr.status + " - " + xhr.statusText);
}
status将打印http状态代码,例如404、500等
xhr.statusText将打印与代码相关的文本,例如找不到页面、内部服务器错误等

问题在于JQueryAutoComplete.aspx中的声明需要将属性代码文件更改为codebehind


codefile属性阻止它访问.cs,这就是404的来源。

Firebug的网络面板或脚本调试器是否为您提供了任何线索?在您托管函数后,是否成功调用了该函数?因为有时候绝对URL可能会更改。如果我没弄错的话,您想从服务器返回一些对象作为JSON对象并在textbox上使用它吗?如果您这样做了,可能是您忘记了扩展JSON大小限制。如果没有../,我如何重写它?jQuery文件位于应用程序的根目录中。当您以/开头时,url与站点的根目录相对,因此url开头的/。/有点奇怪。如果QueryAutoComplete.aspx位于您站点的根目录中,您是否可以将url写为:/JQueryAutoComplete.aspx/GetAutoCompleteData?我尝试过,它在本地版本中运行正常,但在发布的版本中再次无效。您是否尝试更改错误函数以获取更多信息?返回了什么http代码?我添加了您提到的警报,但它现在什么也不做。