views:

42

answers:

2
<script type="text/javascript">
$(function(){
 $('.update').click(function(){
  $.ajax({
     type: "POST",
     url: "/reporting_results/mark_result",
     data: "id="+$(this).attr("id")+"&check="+$(this).val()+"&user_id=<?=$user_id?>&product=<?=$this->uri->segment(3)?>",
  });
 return true
 });
});
</script>
+6  A: 

Because of a trailing comma, right before the end of your $.ajax options:

 data: "id="+$(this).attr("id")+"&check="+$(this).val()+"&user_id=<?=$user_id?>&product=<?=$this->uri->segment(3)?>", <-- trailing comma, is why
karim79
Bo! Good catch!
spender
This drives me nuts on IE. Gets me all the time
webdestroya
Brill, thanks!!!
Nathan Pitman
A: 

Inside the $.ajax brackets, the this context changes to the ajax action. Can you verify that this is pointing to the original element that initiated the click event? I've done stuff like this before, and I remember needing to prefetch variables before entering the $.ajax block.

$('.update').click(function() {
    var id = $(this).attr('id');
    var value = $(this).val();
    var product = '<?=$this->uri->segment(3)?>';
    $.ajax({
        type: "POST",
        url: "/reporting_results/mark_result",
        data: "id="+id+"&check="+value+"&user_id=<?=$user_id?>&product="+product
    });
});

In javascript, the this reference can be very tricky at times, since it refers to the current javascript contextual object.

Jarrett Meyer