I'm having a problem with my code. the html form wont post the values with AJAX, when pressing the "indsend feedback" button. The jquery code works fine when only including a button with a value inside the form, but when i try to include multiple elements, it no longer works and starts posting an empty array.
The code works fine, when used standalone outside the project.
HTML CODE HERE FOR THE FORM and WHILE LOOP.
<tbody>
<?php
$query = "SELECT * FROM psv2_orders_lines, psv2_orders WHERE psv2_orders_lines.order_id = '$orderid' AND psv2_orders.id = '$orderid'";
$result = mysqli_query($dbCon, $query) or die(mysqli_error($dbCon));
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
?>
<tr>
<td class="text-center">
<!-- // Der laves en echo, hvor der udskrives ordrebilledernes destinationer.. -->
<span class='zoom ex2'>
<img src="img/ordrer/<?php echo $orderid,"-", $rowcompany['company'], " ", $row['product'],"/", $row['style_1'],"1",".jpg";?>"
alt="..." class="img-fluid imgsize">
</span>
<span class='zoom ex2'>
<img src="img/ordrer/<?php echo $orderid,"-", $rowcompany['company'], " ", $row['product'],"/", $row['style_1'],"2",".jpg";?>"
alt="..." class="img-fluid imgsize">
</span>
</td>
<td class="text-center"><?php echo $row['line'];?></td>
<td>
<ul class="list-group">
<li class="list-group-item">
<h5>Style 1</h5>
<?php echo $row['style_1'];?>
</li>
<li class="list-group-item">
<h5>Style 2</h5>
<?php echo $row['style_2']; ?>
</li>
<li class="list-group-item">
<h5>Style 3</h5>
<?php echo $row['style_3']; ?>
</li>
<li class="list-group-item">
<h5>Style 4</h5>
<?php echo $row['style_4']; ?>
</li>
</ul>
</td>
<form method="post" action="feedback.php" class="feedbackknap">
<td class="text-center">
<div class="container">
<div class="form-group">
<textarea class="form-control" rows="10" cols="50" placeholder="Skriv problemet her..."
name="orderrejectcomment"></textarea>
</div>
</div>
</td>
<td class="text-center">
<button type="submit" name="style1" value="hej" class="btn btn-dark">Indsend
feedback</button>
</td>
</form>
</tr>
<?php
}
?>
</tbody>
Here is the jQuery code:
$(document).ready(function() {
$('.feedbackknap').on('submit', function(){
var that = $(this),
url = that.attr('action'),
type = that.attr('method'),
data = {};
that.find('[name]').each(function(index, value) {
var that = $(this),
name = that.attr('name'),
value = that.val();
data[name] = value;
});
$.ajax({
url: url,
type: type,
data: data,
success: function(response) {
console.log(response);
}
});
return false;
});});
PHP action folder:
<?php print_r($_POST); ?>