Reputation: 595
My problem is this, i have created an input text and a button just like in this image:
The system is very simple, you enter a number and you hit go to set in database this possition using ajax. i tried this code with Chrome, Internet Explorer 9 and Edge and Firefox (51.0.1 (32-bit)) but it seems that on firefox the code does not work. What culd be the problem? Here is the javascript code:
<script type="text/javascript">
$(document).ready(function () {
$("#set_image_pos_btn<?php echo $image->id; ?>").click(function () {
event.preventDefault();
var image_id = <?php echo $image->id; ?>;
var image_position = $("#image_position_value<?php echo $image->id; ?>").val();
$.ajax({
url: '<?php echo base_url("image/pozitie"); ?>',
data: {id: image_id, position: image_position},
type: 'POST',
success: function (data) {
$("#image_position_value<?php echo $image->id; ?>").html(data);
}
});
});
});
</script>
And here is the php code:
function pozitie() {
$id = $this->input->post('id');
$position = $this->input->post('position');
if(isset($id)) {
$update = $this->image_model->_update($id, array('position' => $position));
if($update) {
$image = $this->image_model->get_where_row('id', $id);
echo $image->position;
} else {
echo "eroare";
}
}
}
Upvotes: 1
Views: 2167
Reputation: 124
add the e parameter to the click event, then it will work.
click(function (e) {
Also: you should care about error handling.
var jqxhr = $.ajax( "example.php" )
.done(function() {
alert( "success" );
})
.fail(function() {
alert( "error" );
})
.always(function() {
alert( "complete" );
});
Upvotes: 2