bug^君 2017-07-24 13:40 采纳率: 25%
浏览 43

获取ID AJAX不是未定义

i have code, but isn't run in barang.php i have this code :

barang.php

<?php
$p=isset($_GET['act'])?$_GET['act']:null;
switch($p) {
    default :
        echo '':
        break;
    case "edit":
        include "editrefbrg.php";
        break;
}

and in pagination.php i have this code :

paginatio.php

<td>
    <a href="?page=barang&act=edit" target="blank" class="edit" id='.$row["id"].'>
        <i class="glyphicon glyphicon-edit"></i>
    </a>
</td>

for ajax i use this code :

    $(document).on("click",".edit",function(){
        var id = $(this).attr('id');
        
        console.log(id);
        if(confirm("edit Data ?")){
            $.ajax({
                type : "POST",
                data: "id="+id,
                url : "editrefbrg.php?id="+id,
                dataType: "json",
                success: function(result){
                    $(this).attr('id'); 
                }
            })
        }else{
            return false;
        }
    });

in file editbrg.php i'm use this code :

include "config/koneksi.php";
$result ="";
$id = $_GET['id'];
$hasil = mysql_query("SELECT concat(f,'.',g,'.',h,'.',i,'.',j) as id,nm_barang as nama,masa_manfaat as umur FROM ref_barang WHERE  f = SUBSTRING('".$id."',1,2) AND g = SUBSTRING('".$id."',4,2) AND h = SUBSTRING('".$id."',7,2) 
     AND i = SUBSTRING('".$id."',10,2) AND j = SUBSTRING('".$id."',13,3) ");
     $d = mysql_fetch_array($hasil);

echo'$d["id"] ';

but in href error code like :

Notice: Undefined index: id in D:\xampp\htdocs\skripsiphp\editrefbrg.php on line 5

</div>
  • 写回答

1条回答 默认 最新

  • weixin_33728268 2017-07-24 13:41
    关注

    In your ajax you have type:"POST", that should be ajax type:"GET" in pagination.php file because you are accessing from $_GET.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据