2013-03-01 2 views
0

다음은이 튜토리얼을 따르므로 내 문제는 다음과 같습니다. 여기에 몇 가지 테이블이 있습니다.jquery와 ajax를 사용하여 변수 전달하기 PHP

<tr id="<?php echo $id; ?>" class="edit_tr"> 

<td class="edit_td"> 
<span id="first_<?php echo $id; ?>" class="text"><?php echo $kodi; ?></span> 
<input type="text" value="<?php echo $kodi; ?>" class="editbox" id="first_input_<?php echo $id; ?>" /&gt; 
</td> 

<td class="edit_td"> 
<span id="last_<?php echo $id; ?>" class="text"><?php echo $vlera; ?></span> 
<input type="text" value="<?php echo $vlera; ?>" class="editbox" id="last_input_<?php echo $id; ?>"/> 
</td> 

</tr> 

자,이 스크립트입니다 :

<script type="text/javascript"> 
$(document).ready(function() 
{ 
$(".edit_tr").click(function() 
{ 
var ID=$(this).attr('id'); 
$("#first_"+ID).hide(); 
$("#last_"+ID).hide(); 
$("#first_input_"+ID).show(); 
$("#last_input_"+ID).show(); 
}).change(function() 
{ 
var ID=$(this).attr('id'); 
var kodi=$("#first_input_"+ID).val(); 
var vlera=$("#last_input_"+ID).val(); 
var dataString = 'id='+ ID +'&kodi='+kodi+'&vlera='+vlera; 
$("#first_"+ID).html('<img src="load.gif" />'); // Loading image 

if(first.length>0&& last.length>0) 
{ 

$.ajax({ 
type: "POST", 
url: "table_edit_ajax.php", 
data: dataString, 
cache: false, 
success: function(html) 
{ 
$("#first_"+ID).html(first); 
$("#last_"+ID).html(last); 

내가 변수는 바로 그들을 저장하지 않습니다 maybe..because 통과하고 있지 않다 쿼리가 excecute하지 않습니다. 감사

+0

당신이지고 어떤 오류 : –

+0

오류가 없으므로 값을 업데이트 할 수 없습니다. – pyetjegoo

+0

방화 광과 같은 것을 사용할 수 있습니까? 그것은 당신에게 아약스 요청을 보여줄 것입니다 그리고 당신은 당신이 무엇을 게시물을 통해 전달하는지 볼 수 있습니다. – Cito

답변

0

아약스는 serialize 사용하는 것입니다 귀하의 양식 필드를 전달하는 jQuery를에 가장 쉬운 방법 :

data: $("form").serialize(); 

추가 문제는 두 개의 변수, firstlast를 사용하지만, 당신이 그들을 정의하지 않는 것입니다 어딘가에.

$(function() { // This makes the same than $(document).ready(); 
    $(".edit_tr").each(function() { // Instead of assign the click event, we loop through each element 
     var $element = $(this); 
     var id = this.id; 
     var $first = $('#first_' + id); 
     var $last = $('#last_' + id); 
     var $firstInput = $('#first_input_' + id); 
     var $lastInput = $('#last_input_' + id); 
     $element.click(function() { 
      $first.hide();$last.hide(); 
      $firstInput.show();$lastInput.show(); 
     }).change(function() { 
      $first.html('<img src="load.gif" />'); 
      // Here you have an if, but those elements are not defined in the script... 
      // if (first.length > 0 && last.length > 0) { 
      $.post("table_edit_ajax.php", { 
       id : id, 
       kodi : $firstInput.val(), 
       vlera : $lastInput.val() 
      }, function(html) { 
       // Here again the two vars not defined 
       //$first.html(first); 
       //$last.html(last); 
      }); 
      // } 
     }); 
    }); 
}); 
+0

글쎄, 이건 제대로 바꿀 수 없네.이게 내가 할 일이 좀 더 힘들어 .. – pyetjegoo

+0

@pyetjegoo 제 편집을 참조하십시오. – jeroen

0

이 코드를 시도?
관련 문제