2014-01-16 4 views
1

기본 검도 자동 완성 예제는 일치하는 검색 결과가 Ajax 요청을 통해 가져 오는 설정을 보여줍니다. 요청한 리소스가 같은 도메인에 있으면 Ajax 로딩이 제대로 작동하지만 CORS를 지원할 기본 Ajax 요청을 구성 할 수 있는지 궁금하다. $.ajax({})을 직접 사용하는 경우와 같이 Ajax 옵션을 전달하는 방법이 있습니까?크로스 도메인 아약스 요청을 지원하기 위해 검도가 만든 Ajax 요청 구성

$("#products").kendoAutoComplete({ 
         dataTextField: "ProductName", 
         filter: "contains", 
         minLength: 3, 
         dataSource: { 
          type: "odata", 
          serverFiltering: true, 
          serverPaging: true, 
          pageSize: 20, 
          transport: { 
           read: "http://demos.kendoui.com/service/Northwind.svc/Products" 
          } 
         } 
        }); 
       }); 
나는 기본적으로 (예를 울부 짖는 소리) 정규 JQuery와 아약스의 요청으로 요청을 통해 같은 세부적으로 제어 할

:

jQuery.ajax({ 
       url: 'some url', 
       data: {id:id}, 
       contentType: 'application/json', 
       type: "Get", 
       xhrFields: { 
        withCredentials: true 
       }, 
       crossDomain: true 

      }) 
+0

도메인이 다른 경우 클라이언트 도메인에 대해 원격 도메인에서 'Access-Control-Allow-Origin'을 허용해야합니다. 이것은 보안에 관한 것입니다. –

+0

알아요. 서비스가 이미 지원되도록 구성되었습니다. 난 CORS를 지원하는 AJAX 요청을 할 필요가있다. – TGH

+0

헤더에 액세스 토큰을 전달하고 서버 측에서이를 확인할 수있다. 나는 nodejs를 사용하여 편안한 로그인 시스템을 개발 중이다. 간단하게 액세스 토큰을 사용한 통신은 사용자 이름과 암호를 생성했습니다. –

답변

3

이 솔루션은 그래서 같은 Ajax 호출을 래핑하는 방법에 읽기 속성을 할당하는 것입니다 :

$("#search").kendoAutoComplete({ 
     dataTextField: "Name", 
     minLength: 1, 
     dataSource: { 
      type: "json", 
      serverFiltering: true, 
      transport: { 
       read: 
        function(options) { 
         $.ajax({ 
          url: "someUrl", 
          contentType: 'application/json', 
          data: { text: options.data.filter.filters[0].value }, 
          type: "Get", 
          xhrFields: { 
           withCredentials: true 
          }, 
          crossDomain: true, 
          success: function (result) { 
           options.success(result); 
          } 
         }); 
        } 
       } 
      } 
     } 
    }); 

이 당신에게 기본 아약스 동작을 대체 할 수있는 기능을 제공합니다.

3

당신은 beforeSend 방법에 사용자를 설정할 수 있습니다;

$("#products").kendoAutoComplete({ 
     dataTextField: "ProductName", 
     filter: "contains", 
     minLength: 3, 
     dataSource: { 
      type: "odata", 
      serverFiltering: true, 
      serverPaging: true, 
      pageSize: 20, 
      transport: { 
       read: { 
        url: "http://demos.kendoui.com/service/Northwind.svc/Products", 
        type: 'POST', 
        beforeSend: function(req) { 
         req.setRequestHeader('Auth', your_token); 
        } 
       } 
      } 
     } 
    }); 
}); 
3

아래와 같이 데이터 소스 정의에 대해 독자의 속성 "xhrFields"에 대해 withCredentials를 true로 설정하면됩니다.

dataSource: { 
        transport: { 
         read: { 
          xhrFields: { 
           withCredentials: true 
          }, 
          url: serviceURL 
         } 
        } 
       } 

확인 확실히 당신은 이미 대상 서버에있는 고르 설정에서 = 사실SupportsCredentials을 설정했습니다.
희망이 있습니다