2009-11-10 7 views
0

the help of members from this post으로 프로토 타입에서 jQuery로 변환되었습니다.IE7/8에서 jQuery 업데이트가 작동하지 않습니다.

function jsUpdateCart(){ 
    var parameter_string = ''; 
    allNodes = document.getElementsByClassName("process"); 
    for(i = 0; i < allNodes.length; i++) { 
    var tempid = allNodes[i].id; 
    var temp = new Array; 
    temp = tempid.split("_"); 
    var real_id = temp[2]; 
    var real_value = allNodes[i].value; 
    parameter_string += real_id +':'+real_value+','; 
    } 

    var params = 'ids='+parameter_string; 

    $.ajax({ 
    type: "POST", 
    url: "http://127.0.0.1/codeigniter_shopping/index.php/welcome/ajax_cart", 
    data: params, 
    success: function(r) { 
    $('#ajax_msg').html(r); 
    location.reload(true); 
    } 
}); 

} 



function jsRemoveProduct(id){ 
    var params = 'id='+id; 
    $.ajax({ 
    type: "POST", 
    url: "http://127.0.0.1/codeigniter_shopping/index.php/welcome/ajax_cart_remove", 
    data: params, 
    success: function(r) { 
    $('#ajax_msg').html(r); 
    location.reload(true); 
    } 
}); 
} 

ajax_cart_remove는 파이어 폭스와 IE 모두에서 작동하지만 업데이트는 파이어 폭스와 함께 작동하지만 IE 7/8하지 않습니다.

아무도 나에게 약간의 제안을 주실 수 있습니까?

원래 prototype code here을 볼 수 있습니다.

컨트롤러의 ajax_cart 및 ajax_cart_remove는 다음과 같습니다.

function ajax_cart(){ 
    $this->MOrders->updateCartAjax($this->input->post('ids')); 
    } 

    function ajax_cart_remove(){ 
    $this->MOrders->removeLineItem($this->input->post('id')); 
    } 

MOder 용 모델은 다음과 같습니다. 다음

function removeLineItem($id){ 
    $id = id_clean($id); 
    $totalprice = 0; 
    $cart = $_SESSION['cart']; 
    if (isset($cart[$id])){ 
     unset($cart[$id]); 
     foreach ($cart as $id => $product){ 
      $totalprice += $product['price'] * $product['count']; 
     }  
     $_SESSION['totalprice'] = $this->format_currency($totalprice); 
     $_SESSION['cart'] = $cart; 

     echo "Product removed."; 
    }else{ 
     echo "Product not in cart!"; 
    } 
} 

function updateCartAjax($idlist){ 
    $cart = $_SESSION['cart']; 
    $records = explode(',',$idlist); 
    $updated = 0; 
    $totalprice = $_SESSION['totalprice']; 

    if (count($records)){ 
     foreach ($records as $record){ 
      if (strlen($record)){ 
       $fields = explode(":",$record); 
       $id = id_clean($fields[0]); 
       $ct = $fields[1]; 

       if ($ct > 0 && $ct != $cart[$id]['count']){ 
        $cart[$id]['count'] = $ct; 
        $updated++; 
       }elseif ($ct == 0){ 
        unset($cart[$id]); 
        $updated++; 
       } 
      } 
     } 

     if ($updated){ 
      $totalprice=0; 
      foreach ($cart as $id => $product){ 
       $totalprice += $product['price'] * $product['count']; 
      }  

      $_SESSION['totalprice'] = $this->format_currency($totalprice); 
      $_SESSION['cart'] = $cart; 

      switch ($updated){ 
       case 0: 
       $string = "No records"; 
       break; 

       case 1: 
       $string = "$updated record"; 
       break; 

       default: 
       $string = "$updated records"; 
       break; 
      } 
      echo "$string updated"; 

     }else{ 
      echo "No changes detected"; 

     } 
    }else{ 
     echo "Nothing to update"; 

    } 
} 

형태의 HTML 출력

<form action="http://127.0.0.1/codeigniter_shopping_copy2/index.php/welcome/checkout" method="post"><table border='1' cellspacing='0' cellpadding='5'> 
<tr valign='top'> 
<td><input type="text" name="li_id[10]" value="1" id="li_id_10" class="process" size="5" /></td> 
<td id='li_name_10'>Dress 1</td> 
<td id='li_price_10'>33.95</td> 
<td id='li_total_10'>33.95</td> 
<td><input type='button' name='delete' value='delete' onclick='jsRemoveProduct(10)'></td> 
</tr> 
<tr valign='top'> 

<td><input type="text" name="li_id[6]" value="2" id="li_id_6" class="process" size="5" /></td> 
<td id='li_name_6'>Shoes 1</td> 
<td id='li_price_6'>23.95</td> 
<td id='li_total_6'>47.90</td> 
<td><input type='button' name='delete' value='delete' onclick='jsRemoveProduct(6)'></td> 
</tr> 
<tr valign='top'> 
<td colspan='3'>&nbsp;</td> 
<td colspan='2'>81.85 
<input type="hidden" name="name" value="total" /> 
<input type="hidden" name="id" value="total" /> 
<input type="hidden" name="value" value="81.85" /> 
</td> 
</tr> 

<tr valign='top'> 
<td colspan='3'>&nbsp;</td> 
<td colspan='2'><input type='button' name='update' value='update' onclick='jsUpdateCart()'/></td> 
</tr> 
<tr valign='top'> 
<td colspan='3'>&nbsp;</td> 
<td colspan='2'><input type="submit" name="submit" value="checkout" /></td> 
</tr> 
</table> 
</form> 
+0

여기서 /는 id가'ajax_msg' 인 요소입니까? –

답변

3

내가 IE가 document.getElementByClassName ("")

allNodes = document.getElementsByClassName("process"); 

를 교체 시도를 지원합니다 생각하지 않습니다

allNodes = $(".process"); 

JQuery 방식입니다. 다음

var params = 'ids='+parameter_string; 

    $.ajax({ 

:

$('#ajax_msg').html(r); 

나 또한 여기에 .ajax 통화에서 브레이크 포인트를 둘 것 :

IE8에서
+1

+1 - IE는 좋은 캐치가 아닙니다. –

+0

고마워요. 그거였다. – shin

0

바로 웹 개발자 툴킷을 가져오고이 라인에서 브레이크 포인트를 넣어 무슨 일이 일어나는 지보십시오.

이 방법을 사용하면 제대로 도착하는지 확인할 수 있습니다. 그렇지 않으면 IE에 문제가 생길 수 있습니다. 여기에 도착하면 여기에 도착하면 서비스로 돌아가는 지 확인할 필요가 있습니다. 첫 번째 URL이 무엇을 말해 줄지. 그런 다음 success 코드를 단계별로 실행하고 오류로 인해 어느 시점에서 건너 뛰는 지 확인하십시오.

이 코드가 문제라는 사실을 알게되면 배운 내용으로 업데이트 할 수 있지만 IE7 및 8에서는이 함수를 사용하여 정상적으로 작동합니다.

관련 문제