dpspn60064 2016-03-10 19:52
浏览 31

PHP sqlite没有用AJAX更新

I'm running Firebug to track what happens when I use Ajax to try to update a lot I have, and everything in firebug is pointing me in the direction that nothing is going wrong - but the log is never updated.

My form + ajax:

<form id="submitTRG" method="GET" action="ajax/submit.php">
                                    <div class="form-group">
                                        <label for="trgID">TRG ID</label>
                                        <input type="text" class="form-control" id="trgID" name="trgID" placeholder="TRG ID #" autofocus><br>
                                        <input type="submit" class="btn btn-success" id="trgIDSubmit" name="Submit">
                                    </div>
                                </form>
                                <script>
                                $(document).ready(function() {
                                   $('#submitTRG').submit( function( event ) {
                                       $.ajax({ // create an AJAX call...
                                           data: $('#submitTRG').serialize(), // serialize the form
                                           type: $('#submitTRG').attr('method'), // GET or POST from the form
                                           url: $('#submitTRG').attr('action'), // the file to call from the form
                                           success: function(response) { // on success..
                                               $('#trgID').val('');
                                           }
                                       });
                                       event.preventDefault();
                                    });
                                });
                                </script>

My PHP catch ajax script:

session_start();

    $date = $_SESSION['date'];
    $tech = $_SESSION['tech'];
    $type = $_SESSION['type'];
    $func = $_SESSION['func'];
    $trg = $_GET['trgID'];

    class MyDB2 extends SQLite3
            {
                function __construct() {
                    $this->open('../DB/test.db');
                } 
            }

    $test = new MyDB2();
    if(!$test){
        echo $test->lastErrorMsg();
    } else {
        echo "Connected<br>";
    }

    echo "inserting: " . $date . " - " . $tech . " - " . $type . " - " . $func . " - " . $trg;
    $sql ="INSERT INTO req (uniqueID,upd,time,tech,type,func,trg) VALUES (NULL, '0', '$date', '$tech', '$type', '$func', '$trg');";

    if(strcmp($trg,'') != 0) {
        $inp = $test->query($sql);
        if(!$inp){
            echo $test->lastErrorMsg();
        } else {
            echo "<br>completed";
        }
    } else {
        //do nothing
    }

    $test->close();

I'm sure this is something small that I am missing but I just cannot figure out what's going on.

In firebug, this is the response I am getting every time the form is ran. Connected<br>inserting: 03/10/2016 - *tech - *type - $func - *id<br>completed

I have checked, double checked, and triple checked my database to make sure the right information is being inputted into the right field - that's not the problem.

  • 写回答

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的速度时间图像)我想问线路信息是什么