2011-10-05 33 views
0

嗨我試圖將我的HTML/PHP/JS/XML頁面遷移到一個PHP文件。我能夠單獨成功地使用4個文件創建我的應用程序,但是當我將它們放入一個時,似乎我的js和php處於衝突狀態,並且如果有方法我可以使單選按鈕默認設置爲無選項,因爲我猜猜這就是問題所在。如何阻止一個PHP頁面重新加載並重新加載其屬性?

嗯,我已經解決了有關單選按鈕的問題,無論如何,我試圖讓他們都在一個頁面上,因爲我試圖模仿本地程序的輸出,我意識到這一個,當我看到輸出我第一次嘗試。所以我現在想要做的是在運行php代碼後我想把它們放在一個div中,這樣它們就不會飛到所有的地方。我已經解決了這個部分,但我現在的問題是當我選擇我的選項中的下一個單選按鈕時,先前請求的結果仍然存在,除非我單擊我的提交按鈕。我猜測它與我傳遞給我的html正文的js有關。試圖在js中修復div問題是可以的,但它只是在一瞬間顯示div。

這裏是我的代碼:

<html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <title>Globe2Smac</title> 
    <link rel="stylesheet" href="css/mycss.css" type="text/css"> 
    <script src="js/hide.js" type="text/javascript"></script> 
    </head> 
    <body onLoad=""> 
    <h2>Globe to SMAC Function</h2> 
      <form method="post" action=""> 
      <div> 
      <ul style="list-style:none"> 
       <li><input id="smember" type ="radio" name ="option" value = "SmacMembers" onChange="SMmember()" checked/>SMAC MEMBERS</li> 
       <li><input id="sbalance"type ="radio" name ="option" value = "SmacBalance" onChange="SMbalance()" checked/>SMAC BALANCE QUERY</li> 
       <li><input id="saward" type ="radio" name ="option" value = "SmacAward" onChange="SMaward()" checked/>SMAC AWARD</li> 
       <li><input id="sredemption" type ="radio" name ="option" value = "SmacRedeem" onChange="SMredeem()" checked/>SMAC REDEMPTION</li> 
      </ul> 
       <div>Globe XML RPC Request:</div> 
       <div id="smmember" class="div-border" style="display:none"><textarea id="areamember" name="gmember" value="Member" spellcheck="false"> 
&lt;?xml version="1.0" encoding="UTF-8"?&gt; 
<methodCall> 
<methodName>smac.members</methodName> 
<params> 
<param> 
<value> 
<string> 
&amp;lt;?xml version="1.0"?&amp;gt; 
&amp;lt;globetosmac&amp;gt; 
&amp;lt;functioncode&amp;gt;smac_members&amp;lt;/functioncode&amp;gt; 
&amp;lt;cardnumber&amp;gt;8880999521960565&amp;lt;/cardnumber&amp;gt; 
&amp;lt;transaction_id&amp;gt;12345678&amp;lt;/transaction_id&amp;gt; 
&amp;lt;/globetosmac&amp;gt; 
</string> 
</value> 
</param> 
</params> 
</methodCall></textarea></div> 
       <div id="smbalancequery"class="div-border" style="display:none"><textarea id="areabalance" name="gbalance" value="Balance" spellcheck="false"> 
&lt;?xml version="1.0" encoding="UTF-8"?&gt; 
<methodCall> 
<methodName>smac.balance_query</methodName> 
<params> 
<param><value><string> 
&amp;lt;?xml version="1.0"?&amp;gt; 
&amp;lt;globetosmac&amp;gt; 
&amp;lt;functioncode&amp;gt;smac_balance_query&amp;lt;/functioncode&amp;gt; 
&amp;lt;cardnumber&amp;gt;8880999521960565&amp;lt;/cardnumber&amp;gt; 
&amp;lt;transaction_id&amp;gt;1441795&amp;lt;/transaction_id&amp;gt; 
&amp;lt;birthday&amp;gt;01011900&amp;lt;/birthday&amp;gt; 
&amp;lt;transactiondatetime&amp;gt;2011-09-16 13:43:58&amp;lt;/transactiondatetime&amp;gt; 
&amp;lt;/globetosmac&amp;gt; 
</string></value></param> 
</params> 
</methodCall> 
</textarea></div> 
       <div id="smaward" class="div-border"style="display:none"><textarea id="areaward" name="gaward" value="Award" spellcheck="false"> 
&lt;?xml version="1.0" encoding="UTF-8"?&gt; 
<methodCall> 
<methodName>smac.award_points</methodName> 
<params> 
<param> 
<value> 
<string> 
&amp;lt;?xml version="1.0"?&amp;gt; 
&amp;lt;globetosmac&amp;gt; 
&amp;lt;functioncode&amp;gt;smac_award_points&amp;lt;/functioncode&amp;gt; 
&amp;lt;cardnumber&amp;gt;8880999521060440&amp;lt;/cardnumber&amp;gt; 
&amp;lt;transaction_id&amp;gt;1441795&amp;lt;/transaction_id&amp;gt; 
&amp;lt;transaction_amount&amp;gt;100&amp;lt;/transaction_amount&amp;gt; 
&amp;lt;transaction_code&amp;gt;OFLN-GLOBE&amp;lt;/transaction_code&amp;gt; 
&amp;lt;transactiondatetime&amp;gt;2011-09-22 16:20:58&amp;lt;/transactiondatetime&amp;gt; 
&amp;lt;/globetosmac&amp;gt; 
</string> 
</value> 
</param> 
</params> 
</methodCall></textarea></div> 
       <div id="smredemption" class="div-border"style="display:none"><textarea id="arearedeem" name="gredeem" value="Redeem" spellcheck="false"> 
&lt;?xml version="1.0" encoding="UTF-8"?&gt; 
<methodCall> 
<methodName>smac.redemption_points</methodName> 
<params> 
<param> 
<value> 
<string> 
&amp;lt;?xml version="1.0"?&amp;gt; 
&amp;lt;globetosmac&amp;gt; 
&amp;lt;functioncode&amp;gt;smac_redemption_points&amp;lt;/functioncode&amp;gt; 
&amp;lt;cardnumber&amp;gt;8880999521060440&amp;lt;/cardnumber&amp;gt; 
&amp;lt;transaction_id&amp;gt;1441795&amp;lt;/transaction_id&amp;gt; 
&amp;lt;transaction_amount&amp;gt;10&amp;lt;/transaction_amount&amp;gt; 
&amp;lt;transaction_code&amp;gt;OFLN-GLOBE&amp;lt;/transaction_code&amp;gt; 
&amp;lt;transactiondatetime&amp;gt;20110921 16:20:58&amp;lt;/transactiondatetime&amp;gt; 
&amp;lt;/globetosmac&amp;gt; 
</string> 
</value> 
</param> 
</params> 
</methodCall></textarea></div> 
<div id="submit"><input type="submit" name="Submit" value="Submit Query"></div> 
<div>Globe XML Response:</div> 
<div class="div-border"><?php 
    if($_POST['option'] == "SmacMembers"){ 
    $member = $_POST['gmember']; 
    $URL = 'https://localhost/globe2smac-fh3/api/'; 
    $ch = curl_init($URL); 
    //curl_setopt($ch, CURLOPT_URL, "https://localhost/globe2smac-fh3/api"); 
    curl_setopt($ch, CURLOPT_MUTE, 1); 
    curl_setopt($ch, CURLOPT_USERPWD, "michael:kel"); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
    curl_setopt($ch, CURLOPT_POST, 1); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/html')); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $member); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 2); 
    $MemResult = curl_exec($ch); 
    curl_close($ch); 
    } 
    else if($_POST['option'] == "SmacBalance"){ 
    $balance= $_POST['gbalance']; 
    echo $balance; 
    $URL = "https://localhost/globe2smac-fh3/api/"; 

    $ch = curl_init($URL); 
    curl_setopt($ch, CURLOPT_MUTE, 1); 
    curl_setopt($ch, CURLOPT_USERPWD, "michael:kel"); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
    curl_setopt($ch, CURLOPT_POST, 1); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml')); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, "$balance"); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    $BalResult= curl_exec($ch); 
    curl_close($ch); 

    echo $output; 

    } 
    else if($_POST['option'] == "SmacAward"){ 
    $award=$_POST['gaward']; 
    echo $award; 
    $URL = "https://localhost/globe2smac-fh3/api/"; 

    $ch = curl_init($URL); 
    curl_setopt($ch, CURLOPT_MUTE, 1); 
    curl_setopt($ch, CURLOPT_USERPWD, "michael:kel"); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
    curl_setopt($ch, CURLOPT_POST, 1); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml')); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, "$award"); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    $output = curl_exec($ch); 
    curl_close($ch); 

    echo $output; 
    } 
    else if($_POST['option'] == "SmacRedeem"){ 
    $redeem=$_POST['gredeem']; 
    echo $redeem; 
    $URL = "https://localhost/globe2smac-fh3/api/"; 

    $ch = curl_init($URL); 
    curl_setopt($ch, CURLOPT_MUTE, 1); 
    curl_setopt($ch, CURLOPT_USERPWD, "michael:kel"); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
    curl_setopt($ch, CURLOPT_POST, 1); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml')); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, "$redeem"); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    $RedResult = curl_exec($ch); 
    curl_close($ch); 

    echo $output; 
    } 
    else{ 
    echo('Option not Found'); 
} 
?></div> 
       </div> 
      </form> 
     </body> 
    </html> 

重新更新了我的代碼如下:

<html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <title>Globe2Smac</title> 
    <link rel="stylesheet" href="css/mycss.css" type="text/css"> 
    <script src="js/hide.js" type="text/javascript"></script> 
    </head> 
    <body onLoad="siteLoad();"> 
    <h2>Globe to SMAC Function</h2> 
      <form method="post" action=""> 
      <div> 
      <ul style="list-style:none"> 
       <li><input id="smember" type ="radio" name ="option" value = "SmacMembers" onChange="SMmember()" />SMAC MEMBERS</li> 
       <li><input id="sbalance"type ="radio" name ="option" value = "SmacBalance" onChange="SMbalance()"/>SMAC BALANCE QUERY</li> 
       <li><input id="saward" type ="radio" name ="option" value = "SmacAward" onChange="SMaward()"/>SMAC AWARD</li> 
       <li><input id="sredemption" type ="radio" name ="option" value = "SmacRedeem" onChange="SMredeem()"/>SMAC REDEMPTION</li> 
      </ul> 
       <div>Globe XML RPC Request:</div> 
       <div id="smmember" class="div-border" style="display:none"><textarea id="areamember" name="gmember" value="Member" spellcheck="false"> 
&lt;?xml version="1.0" encoding="UTF-8"?&gt; 
<methodCall> 
<methodName>smac.members</methodName> 
<params> 
<param> 
<value> 
<string> 
&amp;lt;?xml version="1.0"?&amp;gt; 
&amp;lt;globetosmac&amp;gt; 
&amp;lt;functioncode&amp;gt;smac_members&amp;lt;/functioncode&amp;gt; 
&amp;lt;cardnumber&amp;gt;8880999521960565&amp;lt;/cardnumber&amp;gt; 
&amp;lt;transaction_id&amp;gt;12345678&amp;lt;/transaction_id&amp;gt; 
&amp;lt;/globetosmac&amp;gt; 
</string> 
</value> 
</param> 
</params> 
</methodCall></textarea></div> 
       <div id="smbalancequery"class="div-border" style="display:none"><textarea id="areabalance" name="gbalance" value="Balance" spellcheck="false"> 
&lt;?xml version="1.0" encoding="UTF-8"?&gt; 
<methodCall> 
<methodName>smac.balance_query</methodName> 
<params> 
<param><value><string> 
&amp;lt;?xml version="1.0"?&amp;gt; 
&amp;lt;globetosmac&amp;gt; 
&amp;lt;functioncode&amp;gt;smac_balance_query&amp;lt;/functioncode&amp;gt; 
&amp;lt;cardnumber&amp;gt;8880999521960565&amp;lt;/cardnumber&amp;gt; 
&amp;lt;transaction_id&amp;gt;1441795&amp;lt;/transaction_id&amp;gt; 
&amp;lt;birthday&amp;gt;01011900&amp;lt;/birthday&amp;gt; 
&amp;lt;transactiondatetime&amp;gt;2011-09-16 13:43:58&amp;lt;/transactiondatetime&amp;gt; 
&amp;lt;/globetosmac&amp;gt; 
</string></value></param> 
</params> 
</methodCall> 
</textarea></div> 
       <div id="smaward" class="div-border"style="display:none"><textarea id="areaward" name="gaward" value="Award" spellcheck="false"> 
&lt;?xml version="1.0" encoding="UTF-8"?&gt; 
<methodCall> 
<methodName>smac.award_points</methodName> 
<params> 
<param> 
<value> 
<string> 
&amp;lt;?xml version="1.0"?&amp;gt; 
&amp;lt;globetosmac&amp;gt; 
&amp;lt;functioncode&amp;gt;smac_award_points&amp;lt;/functioncode&amp;gt; 
&amp;lt;cardnumber&amp;gt;8880999521060440&amp;lt;/cardnumber&amp;gt; 
&amp;lt;transaction_id&amp;gt;1441795&amp;lt;/transaction_id&amp;gt; 
&amp;lt;transaction_amount&amp;gt;100&amp;lt;/transaction_amount&amp;gt; 
&amp;lt;transaction_code&amp;gt;OFLN-GLOBE&amp;lt;/transaction_code&amp;gt; 
&amp;lt;transactiondatetime&amp;gt;2011-09-22 16:20:58&amp;lt;/transactiondatetime&amp;gt; 
&amp;lt;/globetosmac&amp;gt; 
</string> 
</value> 
</param> 
</params> 
</methodCall></textarea></div> 
       <div id="smredemption" class="div-border"style="display:none"><textarea id="arearedeem" name="gredeem" value="Redeem" spellcheck="false"> 
&lt;?xml version="1.0" encoding="UTF-8"?&gt; 
<methodCall> 
<methodName>smac.redemption_points</methodName> 
<params> 
<param> 
<value> 
<string> 
&amp;lt;?xml version="1.0"?&amp;gt; 
&amp;lt;globetosmac&amp;gt; 
&amp;lt;functioncode&amp;gt;smac_redemption_points&amp;lt;/functioncode&amp;gt; 
&amp;lt;cardnumber&amp;gt;8880999521060440&amp;lt;/cardnumber&amp;gt; 
&amp;lt;transaction_id&amp;gt;1441795&amp;lt;/transaction_id&amp;gt; 
&amp;lt;transaction_amount&amp;gt;10&amp;lt;/transaction_amount&amp;gt; 
&amp;lt;transaction_code&amp;gt;OFLN-GLOBE&amp;lt;/transaction_code&amp;gt; 
&amp;lt;transactiondatetime&amp;gt;20110921 16:20:58&amp;lt;/transactiondatetime&amp;gt; 
&amp;lt;/globetosmac&amp;gt; 
</string> 
</value> 
</param> 
</params> 
</methodCall></textarea></div> 
<div id="submit"><input type="submit" name="Submit" value="Submit XML Request"></div> 
<div>Globe XML Response:</div> 
<div class="div-border"><?php 
    if($_POST['option'] == "SmacMembers"){ 
    $member = $_POST['gmember']; 
    $URL = 'https://localhost/globe2smac-fh3/api/'; 
    $ch = curl_init($URL); 
    //curl_setopt($ch, CURLOPT_URL, "https://localhost/globe2smac-fh3/api"); 
    curl_setopt($ch, CURLOPT_MUTE, 1); 
    curl_setopt($ch, CURLOPT_USERPWD, "michael:kel"); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
    curl_setopt($ch, CURLOPT_POST, 1); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/html')); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $member); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 2); 
    $MemResult = curl_exec($ch); 
    curl_close($ch); 
    echo $MemResult; 
    } 
    else if($_POST['option'] == "SmacBalance"){ 
    $balance= $_POST['gbalance']; 
    $URL = "https://localhost/globe2smac-fh3/api/"; 

    $ch = curl_init($URL); 
    curl_setopt($ch, CURLOPT_MUTE, 1); 
    curl_setopt($ch, CURLOPT_USERPWD, "michael:kel"); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
    curl_setopt($ch, CURLOPT_POST, 1); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml')); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, "$balance"); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    $BalResult= curl_exec($ch); 
    curl_close($ch); 
    echo $BalResult; 

    } 
    else if($_POST['option'] == "SmacAward"){ 
    $award=$_POST['gaward']; 
    echo $award; 
    $URL = "https://localhost/globe2smac-fh3/api/"; 

    $ch = curl_init($URL); 
    curl_setopt($ch, CURLOPT_MUTE, 1); 
    curl_setopt($ch, CURLOPT_USERPWD, "michael:kel"); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
    curl_setopt($ch, CURLOPT_POST, 1); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml')); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, "$award"); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    $Awresult= curl_exec($ch); 
    curl_close($ch); 

    echo $Awresult; 
    } 
    else if($_POST['option'] == "SmacRedeem"){ 
    $redeem=$_POST['gredeem']; 
    echo $redeem; 
    $URL = "https://localhost/globe2smac-fh3/api/"; 

    $ch = curl_init($URL); 
    curl_setopt($ch, CURLOPT_MUTE, 1); 
    curl_setopt($ch, CURLOPT_USERPWD, "michael:kel"); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
    curl_setopt($ch, CURLOPT_POST, 1); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml')); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, "$redeem"); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    $RedResult = curl_exec($ch); 
    curl_close($ch); 

    echo $RedResult; 
    } 
    else{ 
    echo('Processing Requests...'); 
} 
?></div> 
       </div> 
      </form> 
     </body> 
    </html> 
+0

刪除'checked'屬性?對不起,我不清楚是什麼問題 –

回答

0

那麼現在你把所有的單選按鈕設置爲選中狀態;

<input type="radio" ... checked /> 

所有正確的語法首先是:

<input type="radio" ... checked="checked" /> 

而且可以肯定的只有一個單選按鈕被選中(它在單選按鈕:)的性質),或者使用複選框

就一個問題;你爲什麼要把所有東西合併成一個文件?爲了可維護性,大多數情況下分隔你的代碼是一個不錯的主意!

+0

我在我的文章中包含了我對你問題的回覆,因爲我沒有足夠的字符來將它寫爲註釋XD。 –