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 如何让企业微信机器人实现消息汇总整合
    • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
    • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
    • ¥15 TLE9879QXA40 电机驱动
    • ¥20 对于工程问题的非线性数学模型进行线性化
    • ¥15 Mirare PLUS 进行密钥认证?(详解)
    • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
    • ¥20 想用ollama做一个自己的AI数据库
    • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
    • ¥15 请问怎么才能复现这样的图呀