Save form data using AJAX to PHP

前端 未结 2 1001
忘掉有多难
忘掉有多难 2021-01-24 14:08

How can I save the form data in a file or a local db (maybe using AJAX) which send the data via form action to an external db?

The source code for my form is here: http:

2条回答
  •  情歌与酒
    2021-01-24 14:46

    PHP:

    Below is the data retrieved from SERVER

    Server Timezone : ' . date_default_timezone_get() . ''; $current_date = date('d/m/Y == H:i:s '); print "

    Server Time : " . $current_date . "

    "; $dataObject = $_POST; //Fetching all posts echo "
    "; //making the dump look nice in html.
        var_dump($dataObject);
        echo "
    "; //Writes it as json to the file, you can transform it any way you want $json = json_encode($dataObject); file_put_contents('your_data.txt', $json); ?>

    JS:

    
    

提交回复
热议问题