[英]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.