通过ajax发布两个文本框值

时间:2016-01-03 05:49:38

标签: java php ajax

我发布2个项目有问题,即内容'内容1'。 '内容'已成功发布。但是' content1'显示为未定义的索引。我试过下面的代码。包含' content1'的行在发布之前作为评论行。请说明我的错误。

<label class="personal_theme_label">
  <div class="style_personal_img pink waves-effect waves-light z-depth-1">
    <br>
    <br>
    <font style="text-transform: capitalize;">
      pink
    </font>
  </div>
  <input name="personal_theme_color" type="radio" class="with-gap" id="test1" value="pink" />
</label>
<label class="personal_theme_label">
  <div class="style_personal_img purple waves-effect waves-light z-depth-1">
    <br>
    <br>
    <font style="text-transform: capitalize;">
      purple
    </font>
  </div>
  <input name="personal_theme_color" type="radio" class="with-gap" id="test1" value="purple" />
</label>
<label class="personal_theme_label">
  <div class="style_personal_img deep-purple waves-effect waves-light z-depth-1">
    <br>
    <br>
    <font style="text-transform: capitalize;">
      deep-purple
    </font>
  </div>
  <input name="personal_theme_color" type="radio" class="with-gap" id="test1" value="deep-purple" />
</label>
<label class="personal_theme_label">
  <div class="style_personal_img indigo waves-effect waves-light z-depth-1">
    <br>
    <br>
    <font style="text-transform: capitalize;">
      indigo
    </font>
  </div>
  <input name="personal_theme_color" type="radio" class="with-gap" id="test1" value="indigo" />
</label>
<label class="personal_theme_label">
  <div class="style_personal_img blue waves-effect waves-light z-depth-1">
    <br>
    <br>
    <font style="text-transform: capitalize;">
      blue
    </font>
  </div>
  <input name="personal_theme_color" type="radio" class="with-gap" id="test1" value="blue" />
</label>
<label class="personal_theme_label">
  <div class="style_personal_img light-blue waves-effect waves-light z-depth-1">
    <br>
    <br>
    <font style="text-transform: capitalize;">
      light-blue
    </font>
  </div>
  <input name="personal_theme_color" type="radio" class="with-gap" id="test1" value="light-blue" />
</label>
<label class="personal_theme_label">
  <div class="style_personal_img cyan waves-effect waves-light z-depth-1">
    <br>
    <br>
    <font style="text-transform: capitalize;">
      cyan
    </font>
  </div>
  <input name="personal_theme_color" type="radio" class="with-gap" id="test1" value="cyan" />
</label>
<label class="personal_theme_label">
  <div class="style_personal_img green waves-effect waves-light z-depth-1">
    <br>
    <br>
    <font style="text-transform: capitalize;">
      green
    </font>
  </div>
  <input name="personal_theme_color" type="radio" class="with-gap" id="test1" value="green" />
</label>
<label class="personal_theme_label">
  <div class="style_personal_img light-green waves-effect waves-light z-depth-1">
    <br>
    <br>
    <font style="text-transform: capitalize;">
      light-green
    </font>
  </div>
  <input name="personal_theme_color" type="radio" class="with-gap" id="test1" value="light-green" />
</label>
<label class="personal_theme_label">
  <div class="style_personal_img lime waves-effect waves-light z-depth-1">
    <br>
    <br>
    <font style="text-transform: capitalize;">
      lime
    </font>
  </div>
  <input name="personal_theme_color" type="radio" class="with-gap" id="test1" value="lime" />
</label>
<label class="personal_theme_label">
  <div class="style_personal_img yellow waves-effect waves-light z-depth-1">
    <br>
    <br>
    <font style="text-transform: capitalize;">
      yellow
    </font>
  </div>
  <input name="personal_theme_color" type="radio" class="with-gap" id="test1" value="yellow" />
</label>
<label class="personal_theme_label">
  <div class="style_personal_img amber waves-effect waves-light z-depth-1">
    <br>
    <br>
    <font style="text-transform: capitalize;">
      amber
    </font>
  </div>
  <input name="personal_theme_color" type="radio" class="with-gap" id="test1" value="amber" />
</label>
<label class="personal_theme_label">
  <div class="style_personal_img orange waves-effect waves-light z-depth-1">
    <br>
    <br>
    <font style="text-transform: capitalize;">
      orange
    </font>
  </div>
  <input name="personal_theme_color" type="radio" class="with-gap" id="test1" value="orange" />
</label>
<label class="personal_theme_label">
  <div class="style_personal_img deep-orange waves-effect waves-light z-depth-1">
    <br>
    <br>
    <font style="text-transform: capitalize;">
      deep-orange
    </font>
  </div>
  <input name="personal_theme_color" type="radio" class="with-gap" id="test1" value="deep-orange" />
</label>
<label class="personal_theme_label">
  <div class="style_personal_img brown waves-effect waves-light z-depth-1">
    <br>
    <br>
    <font style="text-transform: capitalize;">
      brown
    </font>
  </div>
  <input name="personal_theme_color" type="radio" class="with-gap" id="test1" value="brown" />
</label>
<label class="personal_theme_label">
  <div class="style_personal_img grey waves-effect waves-light z-depth-1">
    <br>
    <br>
    <font style="text-transform: capitalize;">
      grey
    </font>
  </div>
  <input name="personal_theme_color" type="radio" class="with-gap" id="test1" value="grey" />
</label>

1 个答案:

答案 0 :(得分:0)

Oof - 你应该真的缩进你的代码!

那就是说 - 在你当前的代码中,你有以下几行被注释掉:

//var textcontent1 = $("#content1").val();
//var dataString1 = 'content1='+ textcontent1;

是的,那些事情没有确定。

取消注释,然后将数据作为对象传递,如下所示:

$.ajax({
    type: "POST",
    url: "action.php",
    data: {
        'dataString' : dataString,
        'dataString1' : dataString1,
    },
    cache: true,
    // etc.
然后,

action.php会将这两个字符串作为$_POST['dataString']$_POST['dataString1']接收。