DragonWar% 2017-12-04 10:13 采纳率: 0%
浏览 15

通过AJAX发布发布表格

I have the following form which I then send upon submit via AJAX to insert to a MySQL DB through Ajax. All inputbox in form have their own Id and I get them all in my .php process file except the ones "cas" and "dat" that do not seem to go through the AJAX posting process.

The form:

<form id="form">
    <div class="form-group">
        <label class="lab" for="nm">id</label>
        <input disabled type="text" id="id" name="id" class="form-control" placeholder="Id">
    </div>

    <div class="form-group">
        <input type="text" class="form-control" name="cas" id="cas" value="2">
        <input type="text" class="form-control" name="dat" id="dat" value="2017-11-30">
    </div>

    <div class="form-group">
        <label class="lab" for="nm">Product</label> <?php 
        //// function populate ($sql, $class,$name, $id, $title, $value,$option)

        echo populate ("SELECT * FROM product_family order by product_type_id ASC","form-control","nm","nm","Select Product", "product_family", "product_family");?>
    </div>

    <div class="form-group">
        <label class="lab" for="em">Win</label>
        <input type="text" id="em" name="em" class="form-control allow_decimal" placeholder="Win">
    </div>

    <div class="form-group">
        <label class="lab" for="hp">Drop</label>
        <input type="text" id="hp" name="hp" class="form-control allow_decimal" placeholder="Drop">
    </div>

    <div class="form-group">
        <label class="lab" for="ad">Currency</label> <?php 
        //// function populate ($sql, $class,$name, $id, $title, $value,$option)

        echo populate ("SELECT * FROM currency order by id ASC","form-control","ad","ad","Select Currency", "currency", "currency");?>
    </div>
    <button type="button" id="save" class="btn btn-success" onclick="saveData()">Save</button>
    <button type="button" id="update" class="btn btn-warning" onclick="updateData()">Update</button>
</form>

I then have the following JavaScript code triggering the Insert upon "save data" click in order to post the different inputbox values to my .php processing file:

function saveData(){
    var id = $('#id').val();
    var name = $('#nm').val();
    var email = $('#em').val();
    var phone = $('#hp').val();
    var address = $('#ad').val();
    var casino = $("#cas").val()
    var date = $("#dat").val();

    $.post('server.php?p=add', {id:id, nm:name, em:email, hp:phone, ad:address, cas:casino, dat:date}, function(data){
        viewData()
        $('#id').val(' ')
        $('#nm').val(' ')
        $('#em').val(' ')
        $('#hp').val(' ')
        $('#ad').val(' ')

    })
}

function viewData(){
    $.get('server.php', function(data){
        $('tbody').html(data)
    })
}

Then I try to read my "$_post" values on the PHP side:

if($page=='add'){
    try{
        $id = $_POST['id'];
        $nm = $_POST['nm'];
        $em = $_POST['em'];
        $hp = $_POST['hp'];
        $ad = $_POST['ad'];        
        $casino_id =  $_POST['cas'];
        $date =  $_POST['dat'];       
 }

I perfectly get all variables except the dat and cas posts that do no appear in the $_post list. Listing all $_Post the following way:

$myfile = fopen("LOGPOST.txt", "w") or die("Unable to open file!");
        foreach ($_POST as $key => $value){
        $txt= $txt."{$key} = {$value}//";

gives the following output: id = //nm = F&B Sales//em = 1000//hp = 500//ad = EUR//

What am I doing wrong?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭
    • ¥15 2020长安杯与连接网探
    • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么