我想通过传递php中的所有文本框值来进行ajax调用

时间:2016-03-19 09:45:28

标签: javascript php jquery ajax

当我选择到目前为止时,我想为员工姓名进行ajax调用我希望员工姓名是客户名称,位置,日期和日期的组合。所以如何进行ajax调用在文本框?

<form> 
    <fieldset>
        <div class="row">
            <section class="col col-2">
                <label class="select">
                    <select name="place1" id="parent_cat">
                        <option  selected="" disabled="">Client Name</option>
                            <?php 
                            $sql1="select * from m_client order by client_name";
                            $res1=mysql_query($sql1);
                            while($row1=mysql_fetch_array($res1))   {
                            ?>
                                <option value="<?php echo $row1['a_id']; ?>"><?php echo $row1['client_name']; ?></option>
                            <?php  }?>
                        </select> <i></i> 
                    </label>
            </section>
            <section class="col col-2">
                <label class="select">
                    <select name="sub_cat" id="sub_cat">
                        <option  selected="" disabled="">Location</option>
                    </select>
                </label>
            </section>
            <section class="col col-2">
                <label class="input"> <i class="icon-append fa fa-calendar"></i>
                    <input type="text" name="f1" autocomplete="off" placeholder="From Date" id="datepicker-10" data-dateformat='dd-mm-yy'>
                </label>
            </section>
            <section class="col col-2">
                <label class="input"> <i class="icon-append fa fa-calendar"></i>
                    <input type="text" name="f2" autocomplete="off" placeholder="To Date" id="datepicker-11" data-dateformat='dd-mm-yy'>
                </label>
            </section>                        
            <section class="col col-3">
                <label class="select">
                    <select name="emp_name" id="emp_name">
                        <option  selected="" disabled="">Employee Name</option>
                    </select>
                </label>
            </section>
        </div>
    </fieldset>
    <input type="submit" name="submit" value="Submit Details" >
</form>

Javascript代码是:

<script type="text/javascript"> 
    $('.todate').click(function() { 
        var val1 = $('.client_name').val(); 
        var val2 = $('.client_location').val(); 
        var val3 = $('.from_date').val(); 
        var val4 = $('.to_date').val(); 
        $.ajax({ 
            type: 'POST', 
            url: 'process.php', 
            data: { 
                text1: val1, text2: val2 , text3: val3, text4: val4 }, 
                success: function(response) { 
                $('#emp_name').html(response); 
            } 
        }); 
    }); 
</script>

1 个答案:

答案 0 :(得分:0)

如果您使用日期选择器,要选择日期,请使用onSelect事件  例如。

 $("#dt").datepicker({
    onSelect: function(dateText, inst) {

    //write you ajax here
    } 
    });