0

我有一个 Framework7 模板。我想在页面加载时调用网络服务。我在 js 文件中的代码是:

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

但是当页面加载不做任何事情时。当我在另一个 html 文件上尝试我的脚本时,它工作正常。你能帮助我吗?谢谢你。

4

3 回答 3

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

确保您的外部页面包含此<div class="page" data-page="cards">

于 2016-03-17T08:54:54.673 回答
0

确保您已初始化myApp并检查您的页面是否 <div data-page="cards" class="page"> 也包含此行,尝试类似 mainView.router.loadContent(ticket);

于 2016-01-28T12:42:09.087 回答
0

试试这个格式

  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()
    });
于 2016-07-15T22:43:35.713 回答