2017-10-19 2 views
0

Ich habe Probleme mit dem Aufruf einer Ruhe-API mit sammyjs. Ich erstelle eine Singlepage-App, und bisher funktioniert es in sammy js, da meine partiellen htmls geladen sind. Aber mein Hauptziel ist auf Aufruf einer Hash-URL Ich möchte eine API aufrufen, um Daten zu erhalten und nachdem die Anfrage fertig ist rendern die Seite (auf Rückruf), aber es wird "jquery.js: 9631 GET http://localhost:8080/home/stats 404()" wenn es versucht, die API anzurufen.Wie führen Sie eine REST-API alle in sammy js

<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> 

Antwort

0

das Problem ist, sammy js Vorgaben der HTTP-Anforderung zu denken, eine Datei war. also habe ich stattdessen jquery ajax benutzt und es hat funktioniert.

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(); 

          }); 
        } 
       }); 
      }); 
Verwandte Themen