ajax 의 data 매개 변수 오류 로 페이지 가 무 너 졌 습 니 다.

오늘 선택 한 표 의 한 줄 의 데 이 터 를 ajax 를 통 해 백 엔 드 에 전송 하려 고 했 지만 사이트 가 무 너 졌 습 니 다.
코드 는 다음 과 같 습 니 다:

$('.icon-edit').click(function (event) {        
    o=$('.icon-edit').index($(this))+1;
    edit.style.display='block';
    //console.log('$(this)',$(this).parent().parent());
    let message=$(this).parent().parent();
    $("#non").val(message.children('td:eq(0)').html());
    $("#name").val(message.children('td:eq(1)').html());
    $("#sex").val(message.children('td:eq(2)').html());
    $("#age").val(message.children('td:eq(3)').html());
    $("#xueyuan").val(message.children('td:eq(4)').html());
    $("#grade").val(message.children('td:eq(5)').html());
    $("#phone").val(message.children('td:eq(6)').html());
    $("#room").val(message.children('td:eq(7)').html());
    l=message.children('td:eq(0)').html();
  });
  $('#ok').click(function () {
    //event.stopImmediatePropagation();
    let text=$('table');
    id=$('#non').val();
    username=$('#name').val();
    sex=$('#sex').val();
    age=$('#age').val();
    institute=$('#xueyuan').val();
    grade=$('#grade').val();
    phone=$('#phone').val();
    hlbhl=$('#room').val()
    text.find("tr:eq("+o+")").children('td:eq(0)').text(id);
    text.find("tr:eq("+o+")").children('td:eq(1)').text(username);
    text.find("tr:eq("+o+")").children('td:eq(2)').text(sex);
    text.find("tr:eq("+o+")").children('td:eq(3)').text(age);
    text.find("tr:eq("+o+")").children('td:eq(4)').text(institute);
    text.find("tr:eq("+o+")").children('td:eq(5)').text(grade);
    text.find("tr:eq("+o+")").children('td:eq(6)').text(phone);
    text.find("tr:eq("+o+")").children('td:eq(7)').text(hlbhl);
    $.ajax({
      type: "POST",
      url: "doAction2.php",//       

      data: {
            non:o,
            id: id,
            username: username,
            sex: sex,
            age: age,
            institute: institute,
            grade: grade,
            phone: phone,
            hlbhl: hlbhl
      },//         
      dataType: "json",
      ansync: true,
      ContentType: "application/json; charset=utf-8",
      success: function (msg) {//msg:   
        a=2;
        console.log(a);
      }
    });
    edit.style.display='none';
  });

코드 의 대 의 는 내 가 버튼 ($('icon - edit') 을 클릭 한 다음 에 폼 (edit) 을 팝 업 하 는 것 이다. 폼 은 데이터 가 클릭 에서 유래 한 것 이다. 그리고 표 의 내용 을 수정 하고 확인 버튼 ($('\ ok') 을 클릭 한 후에 폼 데 이 터 를 이전에 클릭 한 줄 의 데 이 터 를 덮어 서 표 의 목적 을 달성 하고 확인 을 클릭 할 때 ajax 를 터치 하여 수 정 된 데 이 터 를 백 엔 드 에 보 내 는 것 이다.데 이 터 를 받 고 데이터 베 이 스 를 업데이트 합 니 다.
결 과 는 페이지 가 잘못 되 었 다 고 보고 하지 않 고 바로 붕괴 되 었 습 니 다. 한참 을 살 펴 보 니 ajax 의 data 매개 변수 가 잘못 되 었 기 때 문 입 니 다. 전에 이렇게 썼 습 니 다.

    id=text.find("tr:eq("+o+")").children('td:eq(0)').text(id);
    username=text.find("tr:eq("+o+")").children('td:eq(1)').text(username);
    sex=text.find("tr:eq("+o+")").children('td:eq(2)').text(sex);
    age=text.find("tr:eq("+o+")").children('td:eq(3)').text(age);
    institute=text.find("tr:eq("+o+")").children('td:eq(4)').text(institute);
    grade=text.find("tr:eq("+o+")").children('td:eq(5)').text(grade);
    phone=text.find("tr:eq("+o+")").children('td:eq(6)').text(phone);
    hlbhl=text.find("tr:eq("+o+")").children('td:eq(7)').text(hlbhl);
    $.ajax({
      type: "POST",
      url: "doAction2.php",//       

      data: {
            non:o,
            id: id,
            username: username,
            sex: sex,
            age: age,
            institute: institute,
            grade: grade,
            phone: phone,
            hlbhl: hlbhl
      },//         
      dataType: "json",
      ansync: true,
      ContentType: "application/json; charset=utf-8",
      success: function (msg) {//msg:   
        a=2;
        console.log(a);
      }
    });
    edit.style.display='none';
  });

위 에서 알 수 있 듯 이 제 가 data 에 보 낸 데 이 터 는 문자열 같은 것 이 아니 라 n. fn. init [td, prevObject: n. fn. init (1), context: document] 입 니 다. 자신의 부주의 와 ajax 에 오류 가 발생 한 상황 에 대한 이해 가 적어 서 코드 를 오래 보고 나 서 야 원인 을 발 견 했 습 니 다. 처음에 매개 변수 로 인 한 것 이 아니 라 고 생각 했 습 니 다.매개 변수 오류 가 기껏해야 얻 은 데이터 가 틀 렸 다 고 생각 하기 때문에 잘못 을 보고 하거나 결과 가 다 르 기 때문에 자신 이 너무 젊다.

좋은 웹페이지 즐겨찾기