我有一个Framework7模板。我想在页面加载时调用when服务。我在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文件上尝试我的脚本时,它工作得很好。你能帮帮我吗?谢谢。
发布于 2016-07-16 06:43:36
尝试此格式
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()
});
https://stackoverflow.com/questions/35039982
复制相似问题