简体   繁体   English

无法使用 jQuery AJAX PHP 从选项值传递值并显示在表上

[英]Can't pass value from option value and display on table using jQuery AJAX PHP

This is the image in inspect element when I clicked the option enter image description here这是当我单击选项在此处输入图像描述时检查元素中的图像

this is the option enter image description here这是在此处输入图片描述的选项

and show an alert enter image description here并显示警报在此处输入图像描述

This is my HTML这是我的 HTML

This is my select tag and option value这是我的选择标签和选项值

<div class="dt_limit">Limit :
    <select id="dt_limit" style="width:60px;" onchange="javascript:load_timesheet_logs_list_dt();">
        <option value="10">10</option>
        <option value="15">15</option>
        <option value="20">20</option>
        <option value="50">50</option>
        <option value="100">100</option>
        <option value="200">200</option>
    </select>
</div>

This is my JavaScript Function.这是我的 JavaScript 函数。 This is the function I created using jQuery AJAX.这是我使用 jQuery AJAX 创建的函数。 The url is my php path directory, I'm not sure about the query variable that I concatenated in url url 是我的 php 路径目录,我不确定我在 url 中连接的查询变量

function load_timesheet_logs_list_dt() {
    var data = $('#dt_limit').val();
    var pathname =location.search;
    var convert_data = parseInt(data);

    $.ajax({
        type: 'GET',
        url: 'attendance/manage',
        data:  ({ data: data}) ,
        success: function(data){
            return data;
        },
        error: function( jqXHR, textStatus, errorThrown){
            alert(errorThrown);
        }
    })
}

This is my PHP Function这是我的 PHP 函数
the $per_page variable is just for experimenting only $per_page 变量仅用于试验
I manually created that variable for showing data, the code works fine but I want to make it dynamic when selecting a value from select tag on my html then show the data on my table depending on the value selected in option tag**我手动创建了用于显示数据的变量,代码工作正常,但我想在从 html 上的 select 标签中选择一个值时使其动态化,然后根据选项标签中选择的值在我的表中显示数据**

function manage() {
    $per_page = $_GET['data'];
    $page_number = (int) $_GET['pageID'];

    if ($page_number > 0) {
        $page_number--;
        $start_record = $page_number * $per_page;
    } else {
        $start_record = $page_number;
    }
}

Change改变

$per_page = 100;

to

$per_page = $_GET['data'];

Get method using get values this one '$_GET['data']'.获取方法使用获取值这个'$_GET['data']'。 tested working good Hope this helps you.测试工作良好希望这对你有帮助。

index.html
====
<div class="dt_limit">Limit :
    <select id="dt_limit" style="width:60px;" onchange="javascript:load_timesheet_logs_list_dt();">
        <option value="10">10</option>
        <option value="15">15</option>
        <option value="20">20</option>
        <option value="50">50</option>
        <option value="100">100</option>
        <option value="200">200</option>
    </select>
</div>

jQuery
======
function load_timesheet_logs_list_dt() {
    var data = $('#dt_limit').val();
    var pathname =location.search;
    var convert_data = parseInt(data);
    var query = window.location.search;

    $.ajax({
        type: 'GET',
        url: query + '/post.php',
        data:  ({ data: data}) ,
        success: function(data){
            return data;
        },
        error: function( jqXHR, textStatus, errorThrown){
            alert(errorThrown);
        }
    })
}

post.php === post.php ===

manage();
function manage() {
    $per_page = 100;
    $page_number = (int) $_GET['data'];

    if ($page_number > 0) {
        $page_number--;
        $start_record = $page_number * $per_page;
    } else {
        $start_record = $page_number;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM