2017-04-14 91 views
0

大家好,任何人都可以幫助我解決這個問題,請發佈整個代碼,因爲我真的是編碼方面的小白,並且已經失去了許多小時尋找正確的答案。如果我想投票給這個遊戲中看到此頁面 http://www.spielonline.ch/spiel.php/Kogama-Ostry.html 的「spielbewertung」的頁面加載從頁面spiel.php的iframe nickolodeonspelheader.php投票後的URL看起來像這樣 http://www.spielonline.ch/nickelodeonspelheader.php/Kogama-Ostry.html這是錯誤的,它應該改變輸入後的數據庫中的數據,並返回到原始父頁面,以便遊戲可以在投票後播放。這是表格代碼:如何在表單提交後刷新頁面?

<table style="display: inline-block;"><tr> 

<td class="top" colspan="1" width="100%"><h2>Spielbewertung</h2></td></tr> 
    <tr><td width="50%" style="align:left;"> 
    <form name="rating" action="" method="post"> 
     <p style="font-family: tahoma; font-size: x-small;"> 
     <b>Spiel bewerten:</b> 
        <select name="number"> 
         <option value="">-</option> 
     <option value="3">3 = sehr schlecht</option> 
     <option value="4">4 = mangelhaft</option> 
     <option value="5">5 = langweilig</option> 
     <option value="6">6 = ausreichend</option> 
     <option value="7">7 = befriedigend</option> 
     <option value="8">8 = gut</option> 
     <option value="9">9 = sehr gut</option> 
     <option value="10">10 = hervorragend</option> 
     </select> 
     <input type="submit" name="vote" value="bewerten" style="cursor: pointer" />   
           </p> 
       </form> 

    </td></tr> 
</table> 

非常感謝您的幫助!

+0

重定向不斷加載網頁一遍遍或我一定做錯了什麼事,給我正確的重定向代碼。 –

回答

0

也許你可以使用這個職位的建議:callback when form submitted using submit() method 並用location.reload()替換alert(「done」);

例如:如果你願意

<!-- Import jQuery in your <head> tag --> 

<head> 
    <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script> 
</head> 

<body> 
<!-- your html source --> 

<table style="display: inline-block;"><tr> 

<td class="top" colspan="1" width="100%"><h2>Spielbewertung</h2></td></tr> 
    <tr><td width="50%" style="align:left;"> 

<!-- Add id attribute for form --> 

    <form id="submit-form" name="rating" action="" method="post"> 
    <p style="font-family: tahoma; font-size: x-small;"> 
    <b>Spiel bewerten:</b> 
       <select name="number"> 
        <option value="">-</option> 
    <option value="3">3 = sehr schlecht</option> 
    <option value="4">4 = mangelhaft</option> 
    <option value="5">5 = langweilig</option> 
    <option value="6">6 = ausreichend</option> 
    <option value="7">7 = befriedigend</option> 
    <option value="8">8 = gut</option> 
    <option value="9">9 = sehr gut</option> 
    <option value="10">10 = hervorragend</option> 
    </select> 
    <input type="submit" name="vote" value="bewerten" style="cursor: pointer" />   
          </p> 
      </form> 

</td></tr> 

<script> 
$form = $("#submit-form"); 
$form.on("submit",function() 
{ 
    alert("submitting.."); 
    //do ajax 
    $.ajax({ 
     url:<submit url>, 
     type:post, 
     success:function() { 
      location.reload(); 
     } 
    }); 
}); 
$form.submit(); 
</script> 

</body> 
+0

你可以更具體請我不明白在那裏的代碼,並需要確切知道我需要把我的網頁,使其工作。 –

+0

'location.reload()'刷新頁面。您只需在提交表單時調用該表單。在這裏,他正在異步提交表單,然後在完成時刷新頁面。 –

+0

我在哪裏可以在輸入行之後或之後放置該ajax腳本?我是否需要在該腳本中填寫某些內容或者是否像這樣工作? –