3

特定のphpスクリプト内には、次のものがあります。

<script>

    function showMember() {

           return $.ajax({ //Perform an asynchronous HTTP (Ajax) request.

                type: 'get',

                //A string containing the URL to which the request is sent.
                url: '<?php echo $this->createUrl('member'); ?>',
    ...

これをphpファイル内に配置すると、これが機能します。

しかし、これは物事を整理するための良い方法ではないようです。私は、このすべてのコードを別の .js ファイルに配置したいと考えています。

これらのシナリオに対処するための適切な方法は何ですか?

4

3 に答える 3

0

JavaScript 関数を呼び出して、URL を関数パラメーターとして送信できます。

showMember(<?php echo $this->createUrl('member'); ?>);

jsでキャッチして使用します。

function showMember(posturl) {
return $.ajax({ //Perform an asynchronous HTTP (Ajax) request.

                type: 'get',

                //A string containing the URL to which the request is sent.
                url: posturl,
于 2013-04-28T13:12:32.690 に答える