2014-11-04 205 views
0

我有以下代碼。它在IE中運行良好,但在Chrome和Firefox中無法運行。沒有顯示錯誤。它只是沒有得到輸入的值。有人可以幫我解決這個問題。提前致謝。

File 'main.php' 
--------------- 

<tr> 
<td width="11%" class="style171"></td> 
<td width="55%" bgcolor="#A8D3FF" class="style171"><strong>APPROVE</strong></td> 
<td width="16%" bgcolor="#A8D3FF" align="center"><input type="radio" name="approve" id="approve" value="1" <?php if ($approve== '1') echo "checked"; ?> /></td> 
<td width="18%"></td> 
</tr> 
<tr> 
<td width="11%" class="style171"></td> 
<td class="style171" bgcolor="#A8D3FF"><strong>NOT APPROVE</strong></td> 
<td bgcolor="#A8D3FF" align="center"><input type="radio" name="approve" id="approve" value="2" onClick="processForm()" <?php if ($approve== '2') echo "checked"; ?> /></td> 
<td width="18%"></td> 
</tr> 
<tr> 
<td width="11%" class="style171"></td> 
<td colspan="2" align="left"><div id="div_data"></div></td> 
<td width="18%"></td> 
</tr> 


<script type="text/javascript"> 

function processForm() 
{ 
    var val = 0; 

    if(window.document.getElementById('approve').checked) 
     var val = 1; 

    $.ajax({ 
     type: 'POST', 
     url: 'not_approved.php', 
     data: "value="+val, 
     cache: false, 
     success: function(html){ 
      $("#div_data").html(html); 
     } 
    }); 
} 

</script> 


File 'not_approved.php' 
----------------------- 

<form id="formt" name="formt" method="post" action=""> 
    <table width="100%" border="0" align="left" cellpadding="1" cellspacing="0" bgcolor="#D8EEFE"> 
    <tbody> 
     <tr> 
     <td colspan="3"><table width="100%" border="1" bordercolor="#33CCFF" cellspacing="0" cellpadding="1"> 
      <tbody> 
      <tr class="style2"> 
       <td align="left"><font color="#FF0000">*</font> Enter your comments here. 
       <table width="430" border="0"> 
        <tr class="style2"> 
        <td width="10" align="left" valign="top"></td> 
        <td width="410" colspan="2" align="left" valign="top"><textarea name="comment" id="comment" cols="45" rows="5"><?php echo $comment; ?></textarea></td>   
        </tr> 
       </table></td> 
      </tr> 
      </tbody> 
     </table></td> 
     </tr> 
    </tbody> 
    </table> 
</form> 

回答

0

試試這個

  function processForm() 
      { 
       var val = 0; 

       if(window.document.getElementById('approve').checked) 
        var val = 1; 

       $.ajax({ 
        type: 'POST', 
        url: 'not_approved.php', 
        data: {value:val}, 
        cache: false, 
        success: function(html){ 
         $("#div_data").html(html); 
        } 
       }); 
      } 

      </script> 

**申請變更**數據

+0

我試過了,但仍然不起作用。它顯示'Notice:Undefined index:fieldname' – anny 2014-11-04 06:52:02

+0

但是我不能在你的代碼中看到'fieldname'。所以你可以提供完整的代碼和html – 2014-11-04 07:54:29

+0

我已經提供了上面的代碼。 Tq – anny 2014-11-04 08:15:44

0

你是在傳遞錯誤的方式做數據如下

data: "{'value':"+val+"}", 

和如果該值是字符串,則

data: "{'value':'"+val+"'}", 

data: JSON.stringify({value:val}) 
+0

我試過'data:JSON.stringify({value:val})',但它在IE中不起作用。另外兩個在IE中運行,但不在Chrome和Firefox中運行。我得到這個錯誤'注意:未定義的索引:fieldname'。 – anny 2014-11-04 07:05:21

0

您的數據變量不能是字符串格式,因爲它是一個變量名。你應該做的是這樣的:

<script type="text/javascript"> 

function processForm() 
{ 
    var val = 0; 

    if(window.document.getElementById('approve').checked) 
     var val = 1; 

    $.ajax({ 
     type: 'POST', 
     url: 'not_approved.php', 
     data: { 
       value: val, 
       } 
     cache: false, 
     success: function(html){ 
      $("#div_data").html(html); 
     } 
    }); 
} 

</script> 

這裏分配給價值變量和分配我們使用冒號這裏腳本變量val值:不是在AJAX =「」。在服務器端,捕獲變量也必須具有相同的名稱,即值。

+0

我試過了代碼,但它在IE中不起作用。多麼奇怪...... – anny 2014-11-04 06:41:43

+0

刪除行'cache:false'然後嘗試。 – 2014-11-04 06:42:55

+0

仍然無法正常工作...... :( – anny 2014-11-04 06:47:48

相關問題