-2
Hello!
I am working with MVC structure and routes and I am trying to open a modal with data from a record to be able to update. For this I created a function in js and put in the update link. This function makes an ajax request that through a route takes me to the controller and this returns me a form page with the data filled. However, when I click on any item in my table only opens the route to the first item. I’ve tried some solutions using jquery switches, but I haven’t seen a solution yet. I would be grateful if someone knew why.
Page with the table:
<tbody class="imagetable">
<?php foreach($images as $image): ?>
<tr>
<td><?=$image['id'];?></td>
<td><?=$image['title'];?></td>
<td><?=$image['urlimage'];?></td>
<td><?=$image['slug'];?></td>
<td>
<a id="updateimg" href="#" action="dbimages/<?=$image['id'];?>/updatepage" onclick="updateimgitem()">Update</a>
<a id="deleteimg" href="#" data-action="dbimages/<?=$image['id'];?>/delete">Delete</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
JS:
function updateimgitem() {
$.post({
url: $('#updateimg').attr('action'),
dataType: 'html',
contentType: false,
processData: false,
beforeSend() {
$('#modal').find('.modal-body').html('Carregando...');
$('#modal').modal('toggle');
},
success(html) {
$('#modal').find('.modal-body').html(html);
},
complete() {
$('#modal').modal('toggle');
},
});
}
PHP:
public function update($args) {
$image = Image::select()->find($args['id']);
$this->renderSrc(
'updateimages',
[
'image'=>$image
]
);
}
Have you checked if the URL has the right ID? If yes, put the PHP code that receives this call, in the next times do not print the codes type them, make it easy for those who will try to test etc...
– Rogerio Santos
Opa, worth the tip, already edited, it was the first time I posted. But I put the parts that interact now. It has the form still, but it only takes the record data and puts on the page, ta working beauty pq when adding an item it works normal. The problem is the url and the same route, or something in the modal.
– Marcelo Renato