2012-04-26 5 views
0

일반 핸들러가 있으므로 jquery.ui 자동 완성을 사용할 수 있지만 핸들러가 실행되지 않습니다.일반 핸들러가 실행되지 않음

Heres는 내 코드 : ASPX

<%--------- -------- Autocomplete ----------- --%> 
<link type="text/css" href="../css/ui-lightness/jquery.ui.all.css" rel="stylesheet" /> 
<script type="text/javascript" src="../js/jquery.ui.widget.js"></script> 
<script type="text/javascript" src="../js/jquery.ui.position.js"></script> 
<script type="text/javascript" src="../js/jquery.ui.autocomplete.js"></script> 
<link href="../css/demos.css" rel="stylesheet" type="text/css" /> 
<script type="text/javascript"> 

    function jqueryUI_autocomplete_update_backgroundColor(textbox) { 
     var loginId = $(textbox).next().val(); 

     if (!textbox.disabled && loginId == "") 
      textbox.style.backgroundColor = "#ff9999"; 
     else 
      textbox.style.backgroundColor = ""; 
    } 

    $(function() { 
     $("#user").autocomplete({ 
      source: "Handler1.ashx", 
      minLength: 1, 
      select: function (event, ui) { 
       $(this).next().val(ui.item.id); 
       $("input[id=UserId]")[0].value = ui.item.id; 
       $("input[id=DisplayName]")[0].value = ui.item.value; 
       jqueryUI_autocomplete_update_backgroundColor(this); 
      }, 

      search: function (event, ui) { 
       $(this).next().val(''); 
       $("input[id=UserId]")[0].value = ''; 
       $("input[id=DisplayName]")[0].value = ''; 
       jqueryUI_autocomplete_update_backgroundColor(this); 
      } 
     }) 

      $("#user").data("autocomplete")._renderItem = function (ul, item) 
      { 
       item.label = item.label.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + $.ui.autocomplete.escapeRegex(this.term) + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<strong>$1</strong>"); 
       return $("<li></li>") 
       .data("item.autocomplete", item) 
       .append("<a>" + item.label + "</a>") 
       .appendTo(ul); 
      }; 

    }); 
</script> 

Handler1.ashx

/// <summary> 
/// Summary description for Handler1 
/// </summary> 
/// 
[WebService(Namespace = "http://tempuri.org/")] 
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 

public class Handler1 : IHttpHandler 
{ 

    public void ProcessRequest(HttpContext context) 
    { 
     IList<Project_Data.User> usersList = Project_BLL.Users.ListUsers(); 
     var data = new List<Project_BLL.Users>(); 

     foreach (Project_Data.User user in usersList) 
     { 
      data = new List<Project_BLL.Users>{ 
       new Project_BLL.Users {UserId = user.Id.ToString(), DisplayName = user.Name} 
      }; 
     } 

     int limit = 10; 
     if (HttpContext.Current.Request.QueryString["limit"] != null) 
      limit = Convert.ToInt32(HttpContext.Current.Request.QueryString["limit"]); 

     string q = ""; 
     if (HttpContext.Current.Request.QueryString["term"] != null) 
      q = HttpContext.Current.Request.QueryString["term"]; 

     List<Project_BLL.Users> result = null; 
     var sb = new StringBuilder(); 
     if (q.Trim() != "") 
     { 
      var query = data.Where(p => p.DisplayName.ToLower().Contains(q.ToLower())) 
       .OrderBy(p => p.DisplayName); 
      result = query.Take(limit).ToList(); 

      foreach (var item in result) 
       sb.AppendFormat("{0}{1}|{2}", (sb.Length > 0 ? "\n" : ""), item.DisplayName, item.UserId); 
     } 

     context.Response.ContentType = "text/plan"; 
     context.Response.Write(JsonConvert.SerializeObject(result.Select(u => new { id = u.UserId, value = u.DisplayName }).ToList())); 

    } 

Webconfig

<configuration> 
    <system.web> 
    <compilation debug="true" targetFramework="4.0"/> 
    <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/> 

    <authentication mode="Forms"> 
     <forms name="TestAuthCookie" loginUrl="login.aspx" timeout="1500"> 
     </forms> 
    </authentication> 

    <authorization> 
     <deny users="?"/> 
    </authorization> 
    </system.web> 

    <location path="images"> 
    <system.web> 
     <authorization> 
     <allow users="*" /> 
     </authorization> 
    </system.web> 
    </location> 

    <location path="App_Themes"> 
    <system.web> 
     <authorization> 
     <allow users="*" /> 
     </authorization> 
    </system.web> 
    </location> 

    <location path="js"> 
    <system.web> 
     <authorization> 
     <allow users="*" /> 
     </authorization> 
    </system.web> 
    </location> 

    <location path="css"> 
    <system.web> 
     <authorization> 
     <allow users="*" /> 
     </authorization> 
    </system.web> 
    </location> 

</configuration> 
+0

에 대한 완벽한 레퍼런스 당신은 당신의 Web.config를 게재 할 수 있습니까? – 2GDev

+0

방금 ​​추가했습니다 .. – Luis

답변

0

시도 그것을 정의해야합니다 작업 :

$(function() { 
     $("#user").autocomplete({ 
      source: function(request, response) { 
       $.ajax({ 
        url: "handler1.ashx", 
        data: { 
         foo: request.term 
        }, 
       }); 
      }, 


      minLength: 1, 
      select: function (event, ui) { 
       $(this).next().val(ui.item.id); 
       $("input[id=UserId]")[0].value = ui.item.id; 
       $("input[id=DisplayName]")[0].value = ui.item.value; 
       jqueryUI_autocomplete_update_backgroundColor(this); 
      }, 

here 당신이 일하는 예를 찾을 수 있습니다 (소스보기) JQuery와에서

사이트 :

자동 완성은 소스 옵션을 지정하여 다양한 데이터 소스에서 작동하도록 사용자 정의 할 수 있습니다. 데이터 소스가 될 수 있습니다 :

  • 콜백
  • 당신은 포스트를 만들어 콜백을 지정해야합니다/URL을 지정하는 로컬 데이터

  • 문자열과

    • 배열 너의 구급차에 가라.

      Here $ 아약스

      콜백

  • +0

    그걸 시도했지만 작동하지 않았다. – Luis

    +0

    답변 됨 편집 된 모습 ... – 2GDev

    +0

    무엇을 해야할지 모르겠다. 왜 전화가 안되는지, 왜 전화가 왔는지 확인하기 위해 중단 점을 가지고있다. – Luis

    0

    곳의 web.config에 httpHandlers 섹션입니까? 당신이 원하는 경우 처리기는 소스 변경의 Web.config에

    +0

    또는 처리기의 끝점을 ASHX로 지정하십시오. 실제로 Handler1이 코드 숨김으로 사용하는 ASHX 컨테이너 (실제로 '페이지'가 아님)입니다. –

    +0

    내 처리기가 ashx 파일 – Luis

    +0

    인데 webconfig에서이 값을 설정하기 만하면됩니다. 오류 : 'Handler1'유형을로드 할 수 없습니다. – Luis

    관련 문제