0

在这里,我附上了我的代码图像。单击链接时,我需要在同一页面上发布一个 ID,并且还需要弹出一个引导模型窗口。我使用了几种方法。该值在控制台和火灾错误检查中可用。但我无法使用$_GET,$_POST$_REQUEST方法获取 id。任何你能帮助我吗?

<td><p data-placement="top" data-toggle="tooltip"  title="Edit"><button class="btn btn-primary btn-xs" data-title="Edit" data-toggle="modal" data-target="#edit" id="edit-button" data-id="26" ><span class="fa fa-pencil"></span></button></p></td>

<script>
$('#edit-button').click(function(){
    var eid = $(this).data('id');
    $.ajax
    ({ 
        url: 'managers.php',
        data: {"eid": eid},
        type: 'post',
        success: function(result)
        {
            console.log(eid);
        }
    });
});
</script>

在此处输入图像描述

4

1 回答 1

1

ajax 请求似乎成功但返回整个页面而不是您需要的特定数据。为了减轻对请求方法 (POST) 和特定变量 (eid) 存在的检查,并且在发回任何数据之前,清除输出缓冲区 (ob_clean) - 继续处理,然后退出/死亡。

<?php

    if( $_SERVER['REQUEST_METHOD']=='POST' && isset( $_POST['eid'] ) ){
        ob_clean();

        /* other code presumably to do something with POSTed data */

        /* send some sort of response */
        echo $_POST['eid'];


        exit();
    }

?>

仅返回所需数据而不是整个页面的完整示例。

<html>
  <head>
    <script src="//code.jquery.com/jquery-latest.js" type="text/javascript"></script>
    </head>
    <body>
        <p>This HTML data will not be part of the ajax response, only "the value of eid: X"</p>


        <input type='button' id='edit-button' data-id=303 value='Edit' />
        <script>
        $('#edit-button').click(function(){
            var eid = $(this).data('id');
            $.ajax
            ({ 
                url: 'simplejquery.php',/* chenge this to suit your url */
                data: {"eid": eid},
                type: 'post',
                success: function(result)
                {
                    console.log(result);
                    alert(result)
                }
            });
        });
        </script>
    </body>
</html>
于 2017-05-30T07:12:52.497 回答