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 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路