2014-09-11 2 views
-1

AJAX posts requests 이후에 데이터를 가져 오지 않는 이유는 무엇입니까?아약스 게시물 요청 후 왜 데이터를 가져 오지 못합니까?

내가 AJAX 보내기 포스트 프로세스 사이 양식 입력을 디스 에이블

$('#fid1 input,select').attr('disabled','disbaled'); 

사용할 때

및 AJAX 보내기 포스트 성공 후 양식 입력을 가능

$('#fid1 input,select').removeAttr('disabled'); 

를 사용

index.php

<form method="post" id="fid1"> 
    <input type="checkbox" id="check_box_one" name="color_check" value="one" onclick="sedn_ajax()">1<br> 
    <input type="checkbox" id="check_box_two" name="color_check" value="two" onclick="sedn_ajax()">2<br> 
</form> 

<script> 
function sedn_ajax(){ 
    $('#fid1 input,select').attr('disabled','disbaled'); 
    $('#demoajax').hide(); 
    $('#loading').show(); 
    $.ajax({ 
     url: 'test.php', 
     type: 'POST', 
     data: $('#fid1').serialize(), 
     success: function(data){ 
      $("#loading").fadeOut("slow"); 
      $('#demoajax').show(); 
      $('#demoajax').html(data); 
      $('#fid1 input,select').removeAttr('disabled'); 
      } 
     }); 
    return false; 
} 
$(document).ready(sedn_ajax()); 
</script> 

test.php

<?PHP echo $_POST['color_check']; ?> 
+3

사용 불가 요소는 양식 요청 또는'.serialize()'에서 생성 된 데이터에 포함되지 않습니다. –

+0

어떻게 양식을 비활성화하고 test.php로 데이터를 보낼 수 있습니까? –

+1

양식을 직렬화 한 다음 입력을 비활성화하십시오 (목표가 맞으면). –

답변

1

여러 문제에 변화가 향상 될 수있는 방법을

function sedn_ajax(){ 
    var data = $('#fid1').serialize(); //read the form values before disabled 
    $("#fid1").find('input,select').prop('disabled', true); //set it to true and use prop, not attr 
    $('#demoajax').hide(); 
    $('#loading').show(); 
    $.ajax({ 
     url: 'test.php', 
     type: 'POST', 
     data: data, //use the variable 
     success: function(data){ 
      $("#loading").fadeOut("slow"); 
      $('#demoajax').show(); 
      $('#demoajax').html(data); 
      $("#fid1").find('input,select').prop('disabled', false); //set it to false and use prop() 
      } 
     }); 
    return false; 
} 
$(document).ready(sedn_ajax); //No() 

그리고와

function sedn_ajax(){ 
    $('#fid1 input,select').attr('disabled','disbaled'); //spelled disbaled wrong - lucky it is truthy. You also are slecting all selects in the page, not just the elements in the form. 
    $('#demoajax').hide(); 
    $('#loading').show(); 
    $.ajax({ 
     url: 'test.php', 
     type: 'POST', 
     data: $('#fid1').serialize(), //serialize does not read disabled inputs 
     success: function(data){ 
      $("#loading").fadeOut("slow"); 
      $('#demoajax').show(); 
      $('#demoajax').html(data); 
      $('#fid1 input,select').removeAttr('disabled'); 
      } 
     }); 
    return false; 
} 
$(document).ready(sedn_ajax()); //WRONG should not be() 

이, 매장 look- 업 DOM에 요소를 올려 놓지 마십시오.

관련 문제