0

ドロップダウンの変更時に実行される JavaScript 関数があります。

    <script type="text/javascript">
        $(function()
        {
            // Executes when the status dropdown changes value
            $('select[name="status_dropdown"]').change(function(event)
            {
                var $this = $(event.target);
                var orderId = $this.closest('tr').children('td:eq(0)').text(); // index 0 refers to the "order_id column" in the table

                var result = null;
                var scriptUrl = "ajax_php/update_status.php?order_id=" + orderId + "&status_id=" + this.value;

                $.ajax(
                {
                    url: scriptUrl,
                    type: 'get',
                    dataType: 'html',
                    async: false,
                    success: function(data)
                    {
                       result = data;
                       alert(result);
                   }
                });
            });
        })
    </script>

次のphpコードの戻り値を表示するアラート呼び出しを取得しようとしています(これはtrueです):

    <?php
        .
        .
        .

        return true;
    ?>

アラートはポップアップしません。理由わかる方いますか???

4

3 に答える 3

2

I tried your code with another URL and it's working well. There are three cases:

  • scriptUrl is not calculated properly and doesn't point to your PHP script
  • your server is down
  • you are accessing an URL not served under the same domain as the one of your script (same-origin policy)

You can see detail of your error if you add an error handler to ajax parameters :

error : function(jqXHR, textStatus, errorThrown) {
    alert(errorThrown);
}
于 2013-03-15T15:55:52.650 に答える
1

Return は、php スクリプト内の値のみを返します。それを ajax に出力するには、実際に結果をページに出力する必要があります。この場合は、echo "true";またはprint("true");

于 2013-03-15T15:26:40.817 に答える
-1

これを試して

$(document).ready(function(){
    $('select[name="status_dropdown"]').change(function(event)
        {
            var $this = $(event.target);
            var orderId = $this.closest('tr').children('td:eq(0)').text(); // index 0 refers to the "order_id column" in the table

            var result = null;
            var scriptUrl = "ajax_php/update_status.php?order_id=" + orderId + "&status_id=" + this.value;

            $.ajax(
            {
                url: scriptUrl,
                type: 'get',
                dataType: 'html',
                async: false,
                success: function(data)
                {
                   result = data;
                   alert(result);
               }
            });
        });
});
于 2013-03-15T15:50:33.030 に答える