irwan dwiyanto irwan dwiyanto - 9 months ago 47
Javascript Question

Error fetching data with ajax

I tried to edit the data, with modal boostrap and ajax, but when on the run after the error occurred errors traced the fault is in this script

how to fix it ??

my script

function edit(id) {
url : "<?php echo site_url('edit')?>/" + id,
type: "GET",
dataType: "JSON",
success: function(data)
$('#edit').modal('show'); // show bootstrap modal when complete loaded
error: function (jqXHR, errorThrown)
alert('Error ajax');



$no = 1;
foreach ($user as $row) {
<td><?php echo $no; ?></td>
<td><?php echo $row->nik; ?></td>
<td><?php echo $row->id; ?></td>
<td><?php echo $row->name; ?></td>
<td align="center">
<a href="javascript:void(0)" onclick="editUser('.$row->nik.');" class="btn btn-warning"><span class="glyphicon glyphicon-pencil"></span></a> &nbsp;
<?php $no++; }?>

Answer Source

You have a bit of php/javascript soup. Your href value needs to be enclosed in php tags. Change:



 onclick="editUser('<?php echo $row->nik;?>');"