2017-05-15 11 views
0

현재 서버의 다른 폴더에서 ajax get을 사용하여 jquery 템플릿을 채우려고합니다. 나는 응답 텍스트를 채우고 싶었다. 나는 .tmpl ({..})을 통해 얻는다. 슬프게도 그것은 작동하지 않았다. 여기 내가하는 일이있다.jquery-tmpl on responseText 사용

var a = $.ajax({ 
    method: 'GET', 
    url : 'TemplateUrl/template.html' 
}); 
$.when(a).done(function(){ 
    $(a.responseText).tmpl({...}); 
}); 

에서 responseText 내가이

Uncaught TypeError: Failed to construct 'Text': Please use the 'new' operator, this DOM object constructor cannot be called as a function. 

어쩌면 너희들이 얻을 템플릿을 채우기 위해 시도 할 때이

"<div> 
<td class="ms-formbody"> 
    <!-- FieldName="{{html FieldName}}" 
      FieldInternalName = "{{html FieldName}}" 
      FieldType = "SPFieldText" --> 
    {{html Text}} 
</td> 
</div>" 

처럼 보이는 SharePoint 사이트의에서 HTML의 매우 간단한 조각이다 아이디어. 잘 될 것입니다. 당신이 그것을 인스턴스화하는 대신 함수로 온도()를 호출하려고하기 때문에 사전에 감사하고

인사말 크리스

답변

0

오케이 대답을 얻은 후에 대답은 그렇게 어렵지도 않았고 꽤 논리적이지 않았습니다. 템플릿 엔진은 제대로 작동하려면 스크립트 래퍼가 필요합니다. 따라서 html은 다음과 같아야합니다.

<script type="text/x-jQuery-tmpl"> 
    <div> 
     <td class="ms-formbody"> 
      <!-- FieldName="{{html FieldName}}" 
        FieldInternalName = "{{html FieldName}}" 
        FieldType = "SPFieldText" --> 
      {{html Text}} 
     </td> 
     </div> 
</script> 
0

는 오류가 발생하는 이유입니다.

$ (a.responseText) .tmpl ({...}) 앞에 새 키워드를 사용해보십시오.

+0

빠른 답장을 보내 주셔서 감사합니다. 또한 새로운 $ (a.responseText) .tmpl ({...})을 시도했습니다. 슬프게도 그것은 나에게 같은 결과를 준다. 또한 먼저 수행 var b = new $ (a.responseText); b.tmpl ({...}); 이 작동하지 않습니다. – Chris