通过ajax加载javascript

时间:2015-11-10 16:52:01

标签: javascript php jquery ajax

我通过javascript将以下代码通过javascript加载到网站:

    <div class="modal-body" id="modal-body">
        <?php
            echo $this->Html->script('pdfobject');
        ?>
        <div id="showdoc" style="width: 100%; height: 500px; /*border: 1px solid black;*/">
            <p><?php echo __('It appears you don\'t have Adobe Reader or PDF support in this web browser. ').$this->Html->link(__('Click here to download the file'), array('action' => 'getFile', '?' => array('id' => $data['Voucher']['id'], 'download' => true)), array()); ?></p>
        </div>
        <script type="text/javascript">
            window.onload = function (){
                var myPDF = new PDFObject({         
                    url: "<?php
                        echo $this->Html->url(
                            array(
                                'controller' => 'vouchers',
                                'action' => 'getFile',
                                '?' => array(
                                    'id' => $data['Voucher']['id']
                                    //'download' => 'true'
                                )
                            ),
                            true

                        );
                    ?>",
                pdfOpenParams: {
                    navpanes: 0,
                    toolbar: 0,
                    statusbar: 0,
                    view: 'FitBH,0',//'FitH,0', "FitV"
                    scrollbars: '1',
                    messages: '0'
                    }
                }).embed("showdoc");
            };
        </script>

    </div>
    <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
    </div>

不幸的是,代码没有被执行。如果我通过浏览器直接使用此代码调用php文件,一切正常。 我希望问题是,代码没有执行,因为基页已经加载。任何提示或想法?

1 个答案:

答案 0 :(得分:0)

谢谢Shilly。我加载了var url本身,没有ajax。一切正常。