2016-03-02 74 views
-2
$(".productspecification").autocomplete({ 
      source: '/static/components/autocomplete/listspecification.ashx' 
    }); 

這是我的處理程序如何使用自動完成處理

public void ProcessRequest (HttpContext context) { 
    context.Response.ContentType = "application/javascript"; 
    StringBuilder sbSpecs = new StringBuilder(); 
    string[] lines = System.IO.File.ReadAllLines(HttpContext.Current.Server.MapPath("~/YKIOSK/static/components/autocomplete/specifications.txt")); 
    ArrayList result = new ArrayList(); 
    foreach (string s in lines) 
    { 
     if (s.ToLower().Contains(context.Request.QueryString["term"].ToLower())) 
     { 
      result.Add(s); 
     } 
    } 
    context.Response.Write(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(result)); 
} 

我要到位specifications.txt

+0

where asp.net/asp.net MVC/java? – Anil

+0

它是在asp.net –

回答

0

你需要使用Ajax的添加web服務獲取數據,然後成功創建自動完成項目。

$("#productspecification").autocomplete({ 
    source: function (request, response) { 
     $.ajax({ 
      url: "/static/components/autocomplete/listspecification.ashx", 
      type: "GET", 
      data: request, 
      success: function (data) { 
       response($.map(data, function (el) { 
        return { 
         label: yourLabel, 
         value: Yourvalue 
        }; 
       })); 
      } 
     }); 
    }, 

然後尋找,如何訪問web服務c#,asp.net。

//Use the Web Service that your Web server provides. 
     localhost.Service1 MyService = new localhost.Service1(); 
     //Invoke the public WebMethod of the serice. 
var webdata= MyService.MyMethod(); 

或使用web clienthttp client

Using Client As New HttpClient() 
Dim APIhostUri As String = 「http://localhost:2025/” 
Dim APIResponse As HttpResponseMessage 
Client.BaseAddress = New Uri(APIhostUri) 
+0

我如何在hadler insted的給定文本文件 –

+0

中使用webservice然後查找,如何訪問web服務c#,asp.net。 – Anil

0

首先,我想你應該溝處理程序,並從你的腳本中調用Web服務來得到這樣

$("#productspecification").autocomplete({ 
source: function (request, response) { 
    $.ajax({ 
     url: "url to your web method", 
     type: "GET", 
     data: request, 
     success: function (data) { 
      response($.map(data, function (el) { 
       return { 
        label: yourLabel, 
        value: Yourvalue 
       }; 
      })); 
     } 
    }); 
}, 

,如果你仍然是你自動完成數據想要使用處理程序,那麼你需要插入一個web服務消費者模塊來從web服務獲取數據並作爲響應返回。

就是這樣。

public void ProcessRequest (HttpContext context) { 
context.Response.ContentType = "application/javascript"; 
StringBuilder sbSpecs = new StringBuilder(); 
var wcfClient=new YourWcfProxy(); 
var term=context.Request.QueryString["term"]; 
string[] lines = wcfClient.GetLinesFor(term); 
context.Response.Write(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(result)); 
} 
+0

[WebMethod(EnableSession = true)] public list Fetchspecification() { UploadBLL upb = new UploadBLL(); DataTable dtbrand = upb.Fetchspecification(); 列表 objbrand =新列表(); (dtbrand.Rows.Count> 0) foreach(dtbrand.Rows中的DataRow dr) { Uploaddtlbrand = new Upload(); dtlbrand.specification = dr [「Specification」]。ToString(); objbrand.Add(dtlbrand); } } return objbrand; }這是我的網絡服務 –

+0

首先我可以指出,你應該真的嘗試正確命名你的對象和功能,使之有意義。 其次,您的網絡方法似乎沒有采取任何輸入,但您正在尋找解決一些自動完成數據根據這個服務的'條款'。理想情況下,您的Web服務應該採用參數'term'並返回您從我的問題所瞭解的可能的自動填充單詞。如果那不是真的,那我完全不解 – Gurpreet