2017-10-19 2 views
0

sammyjs로 나머지 API를 호출하는 데 문제가 있습니다. 단일 페이지 응용 프로그램을 만드는 중이며 지금까지 부분 HTML이로드 될 때 sammy js에서 작동합니다. 하지만 내 주요 목표는 해시 URL의 호출에 나는 데이터를 얻으려면 API를 호출하고 요청이 완료되면 (콜백) 페이지를 렌더링하지만, "jquery.js : 9631 GET http://localhost:8080/home/stats 404()"가 나타납니다. api를 호출하려고 할 때.sammy js에서 모두 REST API를 수행하는 방법

<script> 


    $(document).ready(function() { 




     var app = $.sammy('#content', function() { 

      this.use(Sammy.JSON) 


      this.get('#/home', function (context) { 

       //var loadOptions = { type: 'get', dataType: 'json', data: {query: variable}, }; 


       this.load('http://localhost:8080/home/stats') 
        .then(function(items) { 

         $('#content').load("partials/home.html"); 

        }); 



      }); 



     app.run('#/home') 



    });}) 



</script> 

답변

0

문제는 sammy가 http 요청이 파일이라고 생각하는 것입니다. 그래서 jquery ajax를 대신 사용했고 효과가있었습니다.

this.get('#/home', function (context) { 
       $.ajax({ 
        url: "http://localhost:8080/home/stats", 
        type: 'GET', 
        dataType: 'json', 
        success: function(data) { 
         context.app.swap(''); 
         context.load('partials/home.html') 
          .appendTo(context.$element()) 
          .then(function (content) { 
           getFunctionality(); 

          }); 
        } 
       }); 
      });