Why doesn't JSON data load immediately in my HTML page?

pinostack

This is my controller, that takes JSON data to Wordpress :

app.controller('AboutController', function($scope, $http) {

$scope.device=device;
var page_id = 2;

$.ajax({
        url: 'http://davidemilone.com/provawp/?json=get_page&page_id='+page_id+'&callback=?',
        dataType: 'jsonp',
        type: 'GET',
        success: function(data) {

                $scope.page=data.page;
                console.log("contenuto" + $scope.page.content);
        }
});
});

Now, this is my HTML page:

<ons-page ng-controller="AboutController" >
  <ons-toolbar modifier="opacity">
    <div class="left">
      <ons-toolbar-button ng-click="menu.toggle()"><ons-icon icon="ion-navicon-round" fixed-width="false"></ons-icon></ons-toolbar-button>
    </div>
    <div class="center">{{page.title}}</div>
  </ons-toolbar>

  <div class="app-page-content">
    <p class="page-content" ng-bind-html="page.content"></p>
  </div>

Why data doesn't load immediately, it loads only after I click back or when carousel auto slide; what I am doing wrong?

Tomek Sułkowski

You're not using Angular's own tools (e.g. $http service) to comunicate with the server, so the framework doesn't know that the data has changed.

To let Angular know that something on $scope has changed in non-angular way, you should run $scope.$apply(); after you assign the new data.

(To explain the "clicking outside" part: it simply triggers the digest loop - same result as $apply(), that's why the value was updating then)

It would be preferable to use $http service though. I can see you've already injected it into the controller, so it may be a simple mistake, that you used jQuery's ajax function insted. (see Angular docs for $http service for details)

app.controller('AboutController', function($scope, $http) {
    $scope.device=device;
    var page_id = 2;

    var url = 'http://davidemilone.com/provawp/?json=get_page&page_id='+page_id+'&callback=?';
    $http.jsonp(url).then(function(response) {
        console.log(response.data);
        $scope.page = response.data.page;
    });

});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why doesn't my HTML form submit data to MySQL database?

From Dev

Why doesn't my list comprehension code sort things immediately?

From Dev

Why AJAX function doesn't fetch data from DB immediately?

From Dev

My html page not showing my json data

From Dev

socket.IO- why can't my client html page load socket.io.js?

From Dev

Why doesn't my show.html.erb load when clicked on in the index?

From Dev

Why Doesn't My Component Appear On Top of The HTML Page Or Media Player In Codename One

From Dev

HTML - Why doesn't my title show?

From Dev

MeteorJS - Why is my page doesn't re-render when the data changed?

From Dev

Why doesn't this JSON decode into my struct?

From Dev

First page of my website doesn't load correctly "css"

From Dev

Why doesn't XMLHttpRequest doesn't like my JSON?

From Dev

My CSS3 doesn't work in my html page

From Dev

Why can't I load my page in phantomJS?

From Dev

Why doesn't my Erlang shell load rebar dependencies?

From Dev

Why my image doesn't load on contentPane except on CENTER?

From Dev

Why doesn't my custom mouse cursor load after restart?

From Dev

HTML Template does`t load according to page URL.why is that?

From Dev

Why my css code doesn't center the elements on the page?

From Dev

Why doesn't my online users page work correctly?

From Dev

Why my subscribe page doesn't put the fields in MySQL database?

From Dev

Why doesn't my online users page work correctly?

From Dev

HTML , CSS: Table doesn't make my page resize accordingly

From Dev

angularJS - Unable to load API Json response data into my HTML file

From Dev

Why isn't my JS code displaying the message to the HTML page?

From Dev

why my HTML button doesn't trigger start function?

From Dev

Why doesn't my HTML structure work with the CSS Grid layout?

From Dev

Why doesn't my JS add an HTML class?

From Dev

Why doesn't Flask use my custom json_encoder?

Related Related

  1. 1

    Why doesn't my HTML form submit data to MySQL database?

  2. 2

    Why doesn't my list comprehension code sort things immediately?

  3. 3

    Why AJAX function doesn't fetch data from DB immediately?

  4. 4

    My html page not showing my json data

  5. 5

    socket.IO- why can't my client html page load socket.io.js?

  6. 6

    Why doesn't my show.html.erb load when clicked on in the index?

  7. 7

    Why Doesn't My Component Appear On Top of The HTML Page Or Media Player In Codename One

  8. 8

    HTML - Why doesn't my title show?

  9. 9

    MeteorJS - Why is my page doesn't re-render when the data changed?

  10. 10

    Why doesn't this JSON decode into my struct?

  11. 11

    First page of my website doesn't load correctly "css"

  12. 12

    Why doesn't XMLHttpRequest doesn't like my JSON?

  13. 13

    My CSS3 doesn't work in my html page

  14. 14

    Why can't I load my page in phantomJS?

  15. 15

    Why doesn't my Erlang shell load rebar dependencies?

  16. 16

    Why my image doesn't load on contentPane except on CENTER?

  17. 17

    Why doesn't my custom mouse cursor load after restart?

  18. 18

    HTML Template does`t load according to page URL.why is that?

  19. 19

    Why my css code doesn't center the elements on the page?

  20. 20

    Why doesn't my online users page work correctly?

  21. 21

    Why my subscribe page doesn't put the fields in MySQL database?

  22. 22

    Why doesn't my online users page work correctly?

  23. 23

    HTML , CSS: Table doesn't make my page resize accordingly

  24. 24

    angularJS - Unable to load API Json response data into my HTML file

  25. 25

    Why isn't my JS code displaying the message to the HTML page?

  26. 26

    why my HTML button doesn't trigger start function?

  27. 27

    Why doesn't my HTML structure work with the CSS Grid layout?

  28. 28

    Why doesn't my JS add an HTML class?

  29. 29

    Why doesn't Flask use my custom json_encoder?

HotTag

Archive