duanpanbo9476 2014-03-12 06:42
浏览 50
已采纳

当我尝试将值作为Get Ajax传递给php文件时,我的代码中出现了什么错误

I m trying to pass value through get as Ajax request but on the php page it shows indefined index. My code is https://www.dropbox.com/s/88qpmkwmaepa5s4/New%20Text%20Document%20%283%29.txt

Any help is appreciated

JS:

function showDiv(id) {
    loadXMLDoc(id); 
    document.getElementById('pop1').style.display = "block";  
}

function loadXMLDoc(id)
{       
    var xmlhttp;
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            //returned response from ajax to the php page will be in xmlhttp.responseText
            alert(xmlhttp.responseText); // Do whatever you need with the respones
        }
    }
    var selected_row = id   
    window.alert(selected_row);
    xmlhttp.open("GET","view_details.php&row_id=" + encodeURIComponent(selected_row), true);
    xmlhttp.send();
}

PHP:

    <table id="rounded-corner">             
<?php               
    $result = mysql_query("SELECT * FROM mgen_cust_contacts where Cust_code='$j'");
    if($result==FALSE)
        die(mysql_error());
    while ($row = mysql_fetch_array($result)) { ?>

    <tr>                        
        <td><?php echo $row['cust_code'] ?></td>            
        <td><?php echo $row['first_name'] ?></td>
        <td><?php echo $row['last_name'] ?></td>
        <td><?php echo $row['designation'] ?></td>
        <td><?php echo $row['department'] ?></td>
        <td><?php echo $row['phone'] ?></td>
        <td><?php echo $row['mobile'] ?></td>
        <td><?php echo $row['email'] ?></td>            
        <td><a href='#pop1' onclick="showDiv(<?php echo $row['sr_no'] ?>)" class="classname">View</a></td>
        <td><?php echo "<a href='#pop2' class='classname'>Edit</a>" ?></td>         
        <td><?php echo "<a href='#pop3' class='classname'>Delete</a>" ?></td>
    </tr>           
    <?php } } ?>
  • 写回答

1条回答 默认 最新

  • douchun3680 2014-03-12 07:06
    关注

    If you're using the GET method to invoke the script, you access the parameter using $_GET['row_id'], not $_POST['row_id'].

    If you want your script to be invoked either with GET or POST, you can use $_REQUEST['row_id']. All the GET and POST parameters are merged into $_REQUEST.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)