Dimitris
Dimitris

Reputation: 113

Framework7 onPageInit Not Working

I have a Framework7 template. I want to call a webservice when the page load. My code inside the js file is:

myApp.onPageInit('cards', function (page){
    myApp.alert('Alert 1');
            $.ajax({
                type: "POST",
                url: "http://localhost:6032/Api.svc/GetTicket/",
                data: JSON.stringify({UnitType:1,UnitNr:1,PrinterTextNr:1,PrinterNr:0,Copies:1,Logo:0,Delay:0,Host:'pc-pc',Port:8899}),
                processData: true,
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {
                    //Get The Ticket
                    var ticket = data.data.TicketNumber;
                    document.getElementById('myticket').innerHTML = ticket;
                    //End Get The Ticket
                    document.getElementById('ticketBody').style.display = "block";
                    alert(1);
                },
                error: function (xhr) {
                    alert(xhr.responseText);
                }
            });    

}).trigger();

But when the page load doesn't do nothing. When I try my script on another html files, it works fine. Can you help me? Thank you.

Upvotes: 0

Views: 2505

Answers (3)

Mahmoud Mabrouk
Mahmoud Mabrouk

Reputation: 733

try this format

  function Get_MySQL_Category() {
        $.ajax({
            type: "POST",
            url: "http://localhost:6032/Api.svc/GetTicket/",
            data: JSON.stringify({UnitType:1,UnitNr:1,PrinterTextNr:1,PrinterNr:0,Copies:1,Logo:0,Delay:0,Host:'pc-pc',Port:8899}),
            processData: true,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data) {
                //Get The Ticket
                var ticket = data.data.TicketNumber;
                document.getElementById('myticket').innerHTML = ticket;
                //End Get The Ticket
                document.getElementById('ticketBody').style.display = "block";
                alert(1);
            },
            error: function (xhr) {
                alert(xhr.responseText);
            }
        }); 
    };

    myApp.onPageInit('cards', function (page) {
        Get_MySQL_Category()
    });

Upvotes: 0

Ganesh Lore
Ganesh Lore

Reputation: 46

<!-- Views -->
  <div class="views">
    <!-- Your main view -->
    <div class="view view-main">
      <!-- Pages -->
      <div class="pages">
        <div class="page" data-page="cards">
          <div class="page-content">
            page content goes here
          </div>
        </div>
      </div>
    </div>

make sure your external page contains this <div class="page" data-page="cards">

Upvotes: 1

Jerry U
Jerry U

Reputation: 638

Make sure you initialized myApp and check if your page contains this line <div data-page="cards" class="page"> also, try something like mainView.router.loadContent(ticket);

Upvotes: 0

Related Questions