2014-01-08 25 views
0

我的問題是,當單擊插入鏈接: 它很容易返回值沒有ajax函數,但很快把我的ajax函數在這裏它說insertIt沒有定義。我的阿賈克斯不工作在簡單的JavaScript函數

這裏是我的javascript函數:

<?php require_once('include/classes/Author.php'); ?> 
<script language="javascript"> 
function insertIt(pID, pName) 
{ 
    var obj = opener.document.form1.<?php echo $_GET['objName']; ?>; 
    var found = 0; 

    i = 0; 

    while ((i < obj.length) && (found == 0)) 
    { 
     if (obj[ i ].value == pID) { 
      found = 1; 
     } 
     else 
      i++; 
    } 

    if (found == 0) { 
     obj.length++; 
     obj[ obj.length-1 ].value = pID; 
     obj[ obj.length-1 ].text = unescape(pName); 
    } 

    if (window.XMLHttpRequest){ 
     xmlhttp=new XMLHttpRequest(); 
    }else{ 
     xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
    } 
    xmlhttp.onreadystatechange=function() 
    { 
     if (xmlhttp.readyState==4 && xmlhttp.status==200) 
     { 
     // i dont need this... 
     } 
    } 
    xmlhttp.open("get","<?php print WEB_URL; ?>admin/selectVals.php?value="+pID+"&addRemove=add",true); 
    xmlhttp.send(); 
} 

</script> 

這裏是我的html誰我發送的值。

<table> 
    <tbody> 
     <tr> 
     <th>ID</th> 
     <th>Name</th> 
     <th>Action</th> 
     </tr> 
      <tr> 
     <td align="left">1</td> 
     <td align="left">Land's End</td> 
     <td align="left"><a href='javascript:insertIt("57", "Land s End")'>Insert</a></td> 
     </tr> 
     <tr> 
     <td align="left">2</td> 
     <td align="left">Roe v. Wade at 40</td> 
     <td align="left"><a href='javascript:insertIt("58", "Roe v. Wade at 40")'>Insert</a></td> 
     </tr> 
      <tr> 
     <td align="left">3</td> 
     <td align="left">Wagner High and Low</td> 
     <td align="left"><a href='javascript:insertIt("59", "Wagner High and Low")'>Insert</a></td> 
     </tr> 
    </tbody> 
    </table> 
+0

任何尖銳的專家,請????我被困住了親愛的...... –

+0

**危險**:您直接回應用戶輸入到頁面。這使你容易受到[XSS攻擊](http://en.wikipedia.org/wiki/Cross-site_scripting)的影響。 – Quentin

+0

可以在if(xmlhttp.readyState == 4 && xmlhttp.status == 200)之前提醒(xmlhttp.status)以檢查狀態 –

回答

0

,而不是HREF使用的onclick

onclick= 'insertIt("57", "Land s End");return false' href='' 
+0

好吧,讓我試試吧.. –

+0

沒有盧克兄弟...... –

+0

你會得到什麼?你試過把調試器? –