我对 jquery 开发很陌生,并且正在构建一个示例项目来尝试它。我遇到了页面加载问题,因为在加载页面时未执行调用 Web 服务的 JavaScript 函数。我想在页面第一次加载或随后从其他页面中的链接显示时执行 JS 函数。感谢是否有人可以提供这方面的指导。
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="jquery.mobile-1.2.0/demos/css/themes/default/jquery.mobile-1.2.0.css" />
<script type="text/javascript" src="jquery.mobile-1.2.0/demos/js/jquery.js"></script>
<script type="text/javascript" src="jquery.mobile-1.2.0/demos/docs/_assets/js/jqm-docs.js"></script>
<script type="text/javascript" src="jquery.mobile-1.2.0/demos/js/jquery.mobile-1.2.0.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$.ajax("http://localhost:8098/CustomerService.svc/GetCustomerList",
{
beforeSend: function (xhr) {
// $.mobile.showPageLoadingMsg();
},
complete: function () {
// $.mobile.hidePageLoadingMsg();
},
contentType: 'application/json',
dataType: 'jsonp',
jsonp: 'callback',
type: 'GET',
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(xhr.responseText);
//alert(thrownError);
},
success: function (data) {
var result = data.GetCustomerListResult;
$.each(result, function (index, output) {
$('#CustomerList').append('<li data-theme="c"><a href="RewardMember_Find.html?CustomerNo=' + output.CustomerNo + '" data-transition="slide">' +
'<div style="text-align:center; width:80px; float:left;"><img alt="" src="images/' + output.PhotoImage + '"/></div>' +
'<div style="padding-left:85px; color:#575749;"><h2>' + output.CustomerLastName + ' ' + output.CustomerFirstName + '</h2>' +
'<table style="vertical-align:top; font-size:10px;width:100%;">' +
'<tr style="text-align:left;">' +
'<td style="font-weight:bold; width:30%;">Member Since: </td>' +
'<td style="padding-left:5px;color:#FF6600;">' + output.StartDate + '</td>' +
'</tr>' +
'<tr style="text-align:left;">' +
'<td style="font-weight:bold;">Residential Loc: </td>' +
'<td style="text-padding-left:5px;color:#FF6600;">' + output.ResidentialLocation + '</td>' +
'</tr>' +
'</table>' +
'</div>' +
'</a></li>');
});
$('#CustomerList').listview('refresh');
}
});
});