2014-03-12 32 views
0

我試圖通過獲取Ajax請求傳遞值,但是在PHP頁面上顯示了未定義的索引。我的代碼是 https://www.dropbox.com/s/88qpmkwmaepa5s4/New%20Text%20Document%20%283%29.txt當我嘗試將值通過Ajax傳遞給php文件時,我的代碼中出現了什麼錯誤

任何幫助表示讚賞

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

請在這裏發佈您的代碼。 Dropbox只有Javascript,你也需要發佈PHP。 – Barmar

+0

Window.alert顯示正確的值。任何方式的鏈接爲PHP頁面是https://www.dropbox.com/s/lifv6z2ob1l9yvs/New%20Text%20Document%20%284%29.txt – Professor

+1

你必須在這裏發佈你的代碼!不是Dropbox鏈接。 – Barmar

回答

1

如果您使用的GET方法來調用腳本,訪問參數使用$_GET['row_id'],而不是$_POST['row_id']

如果您希望使用GETPOST調用腳本,則可以使用$_REQUEST['row_id']。所有GETPOST參數合併爲$_REQUEST

+0

我在view_details.php中使用$ _GET ['row_id'],但它仍然顯示未定義的索引。 – Professor

+0

請發佈您希望我們爲您提供幫助的真實代碼。 Dropbox鏈接與完全不相關的代碼有什麼關係? – Barmar

+0

編輯我的問題。 – Professor

相關問題