簡體   English   中英

不知道為什么這個簡單的jQuery AJAX腳本在IE7中導致錯誤

[英]At a loss as to why this simple jQuery AJAX script causes an error in IE7

<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>

由於尾隨逗號,就在$ .ajax選項結束之前:

 data: "id="+$(this).attr("id")+"&check="+$(this).val()+"&user_id=<?=$user_id?>&product=<?=$this->uri->segment(3)?>", <-- trailing comma, is why

$.ajax括號內, this上下文更改為ajax操作。 你能否驗證this是否指向發起click事件的原始元素? 我以前做過這樣的事情,我記得在進入$.ajax塊之前需要預取變量。

$('.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
    });
});

在javascript中, this引用有時會非常棘手,因為它引用了當前的javascript上下文對象。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM