简体   繁体   English

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

[英]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. 我试图通过get作为Ajax请求传递值,但是在php页面上它显示了未定义的索引。 My code is https://www.dropbox.com/s/88qpmkwmaepa5s4/New%20Text%20Document%20%283%29.txt 我的代码是https://www.dropbox.com/s/88qpmkwmaepa5s4/New%20Text%20Document%20%283%29.txt

Any help is appreciated 任何帮助表示赞赏

JS: 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: 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'] . 如果使用GET方法调用脚本,则使用$_GET['row_id']而不是$_POST['row_id']来访问参数。

If you want your script to be invoked either with GET or POST , you can use $_REQUEST['row_id'] . 如果希望使用GETPOST调用脚本,则可以使用$_REQUEST['row_id'] All the GET and POST parameters are merged into $_REQUEST . 所有的GETPOST参数都合并到$_REQUEST

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我的 AJAX JQUERY 试图将多个变量值传递给 php 服务器端总是返回错误? - Why is my AJAX JQUERY trying to pass multiple variable values to php server side always returning an error? 当我试图通过jquery和ajax传递它时,删除了css代码 - css code is removed when I tried to pass it through jquery and ajax 无论如何,我可以通过ajax获取PHP数组的值? - Anyway that I can get the values of a PHP array through ajax? 试图通过php和ajax在网页上获取数据 - Trying to get data on a webpage through php and ajax 通过Ajax将JavaScript函数传递到PHP文件 - Pass JavaScript function through Ajax to PHP file (jQuery)尝试使用Ajax查找php文件时出现404错误 - (Jquery) 404 error when trying to find php file with ajax 当我试图确保我的 javascript 代码正常工作时,我在 Google Chrome 上的控制台上收到此错误 - I get this error on my console on Google Chrome when I am trying to make sure that my javascript code is working 尝试使用AJAX将变量值从JavaScript传递到PHP - Trying to pass variable values from JavaScript to PHP using AJAX 我正在尝试通过ajax将参数传递给数据 - i am trying to pass parameter to data through ajax 尝试使用AJAX来获取函数参数并传递给PHP代码 - Trying to use AJAX to grab parameter of function and pass to PHP code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM