当我试图通过Ajax传递值到php文件时,我的代码中的错误是什么

What is the error in my code when i trying to pass values as Get through Ajax to a php file

本文关键字:我的 文件 代码 是什么 错误 php Ajax      更新时间:2023-09-26

我试图通过get作为Ajax请求传递值,但在php页面上它显示了未定义的索引。我的代码是https://www.dropbox.com/s/88qpmkwmaepa5s4/New%20Text%20Document%20%283%29.txt

感谢您的帮助

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 } } ?>

如果使用GET方法调用脚本,则使用$_GET['row_id']而不是$_POST['row_id']访问参数。

如果您希望使用GETPOST调用脚本,您可以使用$_REQUEST['row_id']。所有GETPOST参数合并为$_REQUEST