加载页面时不执行JQuery函数

时间:2012-10-20 02:06:17

标签: jquery html5

我对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');
                }
            });
        });

1 个答案:

答案 0 :(得分:2)

$.ajax("http://localhost:8098/CustomerService.svc/GetCustomerList",
            {

这一行应该是

$.ajax({
       url :  "http://localhost:8098/CustomerService.svc/GetCustomerList",