2017-10-19 5 views
0

sammyjsで残りのAPIを呼び出す際に問題があります。私はシングルページアプリケーションを作成していますが、これまでは部分HTMLが読み込まれているのでsammy jsで動作します。しかし、私の主な目的は、データを取得するためにAPIを呼び出すことを要求されたハッシュされたURLの呼び出しです(コールバックで)ページをレンダリングした後、 "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

問題は、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(); 

          }); 
        } 
       }); 
      }); 
関連する問題