I am using the WordPrewss $wpdb class to insert data into the database. The ajax part works fine but it's not addin the data into the database.
<script>
$("#notes_maker").submit(function(){
event.preventDefault();
var formURL = "<?php echo admin_url('admin-ajax.php')?>";
var notes_editor = $("#notes_area").val();
//var note_timestamp = $(".note_timestamp").text();
$.ajax({
url: formURL,
data: {
'type': 'POST',
'action': 'notes',
'notes_editor1': notes_editor,
'dataType': 'text',
//'note_timestamp': note_timestamp,
},
success: function(data) {
alert("it works");
}
})
});
</script>
<form id="notes_maker" class="notes_section">
<div class="note_timestamp">1.40</div>
<div data-section="notes" class="js-tabs o-wrapper" id="notes">
<textarea name="notes_area1" id="notes_area">
this is some text
</textarea>
<input type="submit" name="submit" value="Save Note"/>
<input type="button" name="cancel_note" value="Cancel"/>
</div>
</form>
functions.php file
function my_ajax_notes() {
if(isset($_REQUEST)) {
$car = $_REQUEST['notes_editor1'];
echo $car;
global $wpdb;
$wpdb->insert(
$wpdb->prefix.`activity_notes`,
[
'text' => $car
]
);
}
}
add_action('wp_ajax_notes', 'my_ajax_notes');
//add_action('wp_ajax_nopriv_notes', 'my_ajax_notes');
