2012-01-17 5 views
0

주석 시스템 용 JavaScript가 있습니다. 그러나 클래스 이름이 "com_submit"인 제출 단추를 클릭하면 페이지가 다시로드되는 것 외에는 아무 것도 발생하지 않습니다. 양식을 비워두고 알림을 제출하더라도 팝업은 표시되지만 그렇지 않습니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까? , .live 내가 .click 사용하여 시도했다.click 함수가 작동하지 않습니다.

$(function() { 

$('.com_submit').live("click", function() { 
    var comment = $("#comment").val(); 
    var user_id = $("#user_id").val(); 
    var perma_id = $("#perma_id").val(); 
    var dataString = 'comment='+ comment + '&user_id='+ user_id + '&perma_id=' + $perma_id; 
    if(comment=='') { 
     alert('Please Give Valid Details'); 
    } 
    else { 
     $("#flash").show(); 
     $("#flash").fadeIn(400).html('<img src="ajax-loader.gif" />Loading Comment...'); 
     $.ajax({ 
      type: "POST", 
      url: "commentajax.php", 
      data: dataString, 
      cache: false, 
      success: function(html){ 
       $("ol#update").append(html); 
       $("ol#update li:first").fadeIn("slow"); 
       $("#flash").hide(); 
      } 
     }); 
    } 
    return false; 
}); 
}); 

예상대로 작동하고 이러한 작업

+0

버튼 선언을 제공 할 수 있습니까? – Praveen

+0

예 버튼이 있습니다 :'' – Sygon

답변

2

링크이므로 런타임 오류가 발생하고 페이지가 다시로드되기 때문에 코드에 오타가 있습니다.

var perma_id = $("#perma_id").val(); 


$(function() { 

$('.com_submit').live("click", function() { 
    var comment = $("#comment").val(); 
    var user_id = $("#user_id").val(); 
    var perma_id = $("#perma_id").val(); 
    var dataString = 'comment='+ comment + '&user_id='+ user_id + '&perma_id=' 
    + perma_id;//<<<------ Here was the typo(You have used $perma_id) 
    if(comment=='') { 
     alert('Please Give Valid Details'); 
    } 
    else { 
     $("#flash").show(); 
     $("#flash").fadeIn(400).html('<img src="ajax-loader.gif" />Loading Comment...'); 
     $.ajax({ 
      type: "POST", 
      url: "commentajax.php", 
      data: dataString, 
      cache: false, 
      success: function(html){ 
       $("ol#update").append(html); 
       $("ol#update li:first").fadeIn("slow"); 
       $("#flash").hide(); 
      } 
     }); 
    } 
    return false; 
}); 
}); 
+0

고맙습니다. 문제가 해결 된 – Sygon

+0

나는 그것이 당신을 도왔다 니 기쁩니다 :) – ShankarSangoli

0

전혀 .bind 없습니다 :

여기 내 코드입니다. 즉, 제출 버튼이 제출 중입니다. 당신이 원하는 것은 정상적인 행동을 멈추는 것입니다. 이 시도 :

$('.com_submit').live("click", function(e) { 
e.preventDefault(); 
. 
. 
. 

을 코드의 상단.

관련 문제