简体   繁体   English

jQuery选项卡,每个选项卡中的表单都提交到数据库

[英]Jquery tabs with forms in each tab submission to database

Hi? i'm having problems with my jquery tabs in my code every time i try to submit data to the database from one of the tabs, the submit returns me to the first tab.besides that an era at the first tab to since the data is read but doesn't submit in reaching at the mysql_query();section . 每次尝试从其中一个选项卡向数据库提交数据时,我的代码中的jquery选项卡都出现问题,提交使我回到第一个选项卡。此外,由于数据是第一个选项卡的时代读取但不提交到达mysql_query(); section。 Please help 请帮忙

if(isset($_POST['submit1'])){

if(isset($_REQUEST['Question1']) AND !empty($_REQUEST['Question1'])) {
//database insert code
 $question='1';         
 $answer =$_POST['Question1'];

    //header("location:question.php?question=$question&answer=$answer"); 
//$quest = $_GET['question'];
//$ans = $_GET['answer'];
$query = "insert into answered_q(quesNo,answer) values('$question','$answer')";
$sql = mysql_query($query);
var_dump($question,$answer);    
}   
   }

  if(isset($_POST['submit2'])){
   if(isset($_REQUEST['Question2']) AND !empty($_REQUEST['Question2'])) {
//database insert code
$question='2';          
$answer =$_POST['Question2'];
$query = "insert into answered_q(quesNo,answer) values('$question','$answer')";
$sql = mysql_query($query);         
var_dump($answer);
 }}

the tabs 标签

  • Question1 问题1
  • Question2 问题2

    <input checked="checked" name="Question1" type="radio" value = "A">Male.</input>
    <input  name="Question1" type="radio" value= "B">Female.</input>
    <p align="center">
<input type="submit" name="submit1" id="submit1" value="Submit" /></p>
    </form></p></div>
    <div id="tabs-2">
<p>
<form id="form2" name="form2" method="post">
    <input checked="checked" name="Question2" type="radio" value = "A">short time span.</input>
    <input  name="Question2" type="radio" value= "B">one year.</input>
    <p align="center">
<input type="submit" name="submit2" id="submit2" value="Submit" /></p>
    </form></p></div>
    </div>

The reason submitting keeps returning you to the first tab is because when you submit a form, it performs a page-redirect, effectively reloading the page. 提交使您一直返回第一个选项卡的原因是,当您提交表单时,它会执行页面重定向,从而有效地重新加载页面。 And when you load the page, it'll automatically choose the first tab as the active one. 并且,当您加载页面时,它将自动选择第一个标签页作为活动标签页。

The way to get around this is to use some type of AJAX-form plugin, such as this one . 解决此问题的方法是使用某种类型的AJAX形式的插件,例如this It makes the form submission an AJAX call, instead of a page redirect. 它使表单提交成为AJAX调用,而不是页面重定向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM