【问题标题】:jquery ajax response stag in post value text box div后值文本框div中的jquery ajax响应标记
【发布时间】:2016-04-13 05:14:45
【问题描述】:

取决于选择选项值更改单击显示文本框名称和显示文本框的数量将随我的 ajax 更改。但我试图在提交按钮中验证该文本框。但是在提交按钮单击时,文本框的值不会保留...

我的问题是 ajax 响应 div 在提交时无法保留该值???

Ajax 响应 div:

<?php
foreach ($technical_skill as $skills){
?>
  <div class="form-group col-md-12">
    <div class="col-md-4">
      <label for="bsl"><?php echo $skills['techskills'];?></label>
    </div>
    <div class="col-md-8">
      <input type="text" class="form-control technicalskill" name = "technicalskill[<?php echo $skills['id']; ?>]" id="bsl">
    </div>
  </div><?php 
  }
?>

Jquery Ajax:

$('#tskill').click(function(){
var parentid = $(this).val();
var text = $('option:selected', this).text();
    $.ajax({
      type:"POST",
      url:"index.php",
      data:{parentid:parentid},
      success:function(response){
        if(parentid == ''){
          $('#tech_head').css('display','none');
        }else{
          $('.tech_skill').html(response);
          $('.tech_group').text('Technical Skill: '+text);
          $('.hide-div').css('display','block');
        }
      }
    });
});

【问题讨论】:

  • 你能发布你的代码吗?

标签: php jquery ajax


【解决方案1】:

简单的解决方案:

将值保存到隐藏字段,并让提交函数验证该值。值应在选择事件后立即保存到隐藏字段。

【讨论】:

    【解决方案2】:

    在发送 ajax 请求之前复制元素数据,以便以后使用它

    例如这里是你的代码

    <div id = 'myDiv'>
        <input type = 'text' id = 'myText' > 
        <input type = 'submit' id = 'submit' >
    </div>
    

    比使用你的 jquery 为

    $('#submit').on('click', function(){
        temp = $('#myDiv');
        //your ajax code here 
        //now check with your elements value as temp.find('#myText').val();
    })
    

    【讨论】:

      猜你喜欢
      • 2014-09-04
      • 2010-11-06
      • 2012-10-02
      • 2014-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-25
      相关资源
      最近更新 更多