I have to post with ajax a form that can contains text and/or message and/or value of checkbox.
All of these post will be sent to a php controller.
I have always use $.post (just for a tchat with text only) and never $.ajax .
Here my form :
if ($member_data->member->isBreeder){
echo '<div id="foalDiscussion"></div>';
echo '<form id="form" action="#" method="post" enctype="multipart/form-data">';
echo '<textarea id="foalNewsTextArea" name="mess_text"></textarea>';
echo '<ul id="mainBreedList">';
foreach ($breeder_foalList as $v){
echo '<li><label class="checkbox-inline"><input type="checkbox" name="foaltarget" value='.$v['foal_id'].'>'.$v['foal_name'].'</label>';
}
echo '</ul>';
<input id="buttonNews" type="file" accept="image/*" name="image" />
<input class="btn btn-secondary" id="button" type="submit" value="Envoyer">
</form>
<div id="err"></div>';
}
I don't know how get data, send data to the controller with $.ajax .
Here my classical $.post chat :
function postFoalMessage(text, foalId, isFoalNews){
$('#foalTextArea').val('');
$.post('http://localhost:8080/MHFManager/src/controller/ChatController.php',
{
mess_text : text,
foal_id : foalId,
isFoalNews : isFoalNews,
},function(data)
{
});
}
Help is welcome!