Skip to content

Instantly share code, notes, and snippets.

@jagroop jagroop/ajax.php
Last active Feb 21, 2018

What would you like to do?
require 'init.php';
$done = false;
if(isset($_POST['username'], $_POST['userjob']))
$data = [
'name' => $_POST['username'],
'job' => $_POST['userjob']
$done = true;
echo json_encode(['success' => $done]);
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<title>Ajax Save to DB example</title>
<script src=""></script>
<form action="" method="POST" role="form">
<div class="form-group">
<label for="">Name</label>
<input type="text" name="name" class="form-control" id="name" placeholder="Input field">
<div class="form-group">
<label for="">Job</label>
<input type="text" name="job" class="form-control" id="job" placeholder="Input field">
<button type="submit" class="btn btn-primary">Submit</button>
var name = $('#name').val();
var job = $('#job').val();
$.post('ajax.php', {username : name, userjob : job}, function(res, s){
if(s === 'success')
if(res.success == true)
return alert('Data inserted !!');
return alert('ERROR');
}, 'json');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.