简体   繁体   中英

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

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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