2013-06-22 2 views
1

내가 지금은 아약스 전송 형태에 문제가 찾아 couldnt는 어디에 오류,내 아약스가 왜 제출하지 않았습니까?

여기

내 HTML :

<form method="post" id="update-profile" name="update-form" action="process.php"> 

<input name="username" type="text" id="username" value="<?php echo $username;?>"/> 
........ 
<input name="update_profile" type="button" class="submit" id="update_profile" value="Update" onclick="return formValidation();" /> 

이 내 자바 스크립트입니다 :

function formValidation() { 
     // other validations here 
    if (validsex(umsex, ufsex)) { 



      $('#mydata').html('Saving ...<img src="../images/loading.gif" />'); 
     $.ajax({ 

     url: "process.php", 
     dataType: 'json' , 
     data :{ id  : document.getElementById('iidd').value, 
       username : document.getElementById('username').value, 
       name  : document.getElementById('name').value, 
        password : document.getElementById('password').value, 
        slist: document.getElementById('slist').value, 
        sexs : sexs, 
        update_profile : "update_profile", 




    type : 'POST', 

     success: function(msg){ 


     $('#mydata').html("<span >saved succefully </span>").delay(3000).fadeOut('fast'); 


     } 
     } 


      }); 


         } 
        } 

      } 
     } 

} 
return false; 
    }        

도 함께 디버깅 한 이

 error: function(jqXHR, textStatus, errorThrown) { 
    console.log(JSON.stringify(jqXHR)); 
    console.log("AJAX error: " + textStatus + ' : ' + errorThrown); 
    }, 

그리고 : AJAX error: undefined : undefined

그래서 나는 그 문제를 안다. 여기

내 process.php :

if (isset($_POST['update_profile'])) { 

    $id = $_POST['iidd']; 
    $username = mysql_real_escape_string($_POST['username']); 
    $name = mysql_real_escape_string($_POST['name']); 
    $password = mysql_real_escape_string($_POST['password']); 
    $country = mysql_real_escape_string($_POST['slist']); 
    $sex = mysql_real_escape_string($_POST['sexs']); 
//update query here 

감사합니다!

+0

이 내가 잘못 될 수있다 중괄호 – Shaddow

+0

에 문제가 있지만, 당신이 보내는 것' id'를 Javascript에서 찾았지만 PHP에서는'$ _POST [ 'iidd']'를 확인하고 있습니까? – element119

+0

@autibyte 내 의견을 보시려면 Sushanth에게주십시오. 나는 너의 제안을 편집했다. –

답변

0

확인 다워야.

@shushanth가 말한 중괄호를 작성한 후이 메시지를 성공 메시지로 변경 한 후 $id = $_POST['id']을 변경했습니다.

난 내 서버 측

 $response_array['status'] = 'success'; 
    }else {$response_array['status'] = 'error';} 
    echo json_encode($response_array); 

에서이 작업을 수행 한 클라이언트 측의이 :

success: function(data){ 
     if(data.status == 'success') 
    // jAlert("Your data is saved succefully"); 
$('#mydata').html("<span >saved succefully!</span>").delay(3000).fadeOut('fast'); 
    else if(data.status == 'error') 
     alert("Error on query!"); 
2

당신은 data 재산

 data: { 
      id: document.getElementById('iidd').value, 
      username: document.getElementById('username').value, 
      name: document.getElementById('name').value, 
      password: document.getElementById('password').value, 
      slist: document.getElementById('slist').value, 
      sexs: sexs, 
      update_profile: "update_profile" 

     }, <---- Missing this 

위해 괄호를 폐쇄하지 않은 그리고 난 당신의 코드에서 다른 모든 여분의 중괄호에 대한 이유를 이해하지 않습니다.

내가 그것을 해결 한

function formValidation() { 
    // other validations here 
    if (validsex(umsex, ufsex)) { 
     $('#mydata').html('Saving ...<img src="../images/loading.gif" />'); 
     $.ajax({ 

      url: "process.php", 
      dataType: 'json', 
      data: { 
       id: document.getElementById('iidd').value, 
       username: document.getElementById('username').value, 
       name: document.getElementById('name').value, 
       password: document.getElementById('password').value, 
       slist: document.getElementById('slist').value, 
       sexs: sexs, 
       update_profile: "update_profile" 
      }, 
      type: 'POST', 
      success: function (msg) { 
       $('#mydata') 
        .html("<span >saved succefully </span>") 
        .delay(3000).fadeOut('fast'); 
      } 

     }); 
    } 
    return false; 
} 
+0

은 id가 있는지 확인하기 위해'$ id = $ _POST [ 'id'];'에 autibyte가 누락되어 편집 된 중괄호를 수행했습니다. 다른 중괄호는 다른 검사 함수에 대해 말했듯이 올바른 것입니다. 그러나 여전히 데이터베이스를 업데이트하지는 않습니다. 이 오류 함수를 사용하는 콘솔에서 {{ "readyState": 4, "responseText": "\ r \ nupdated", "status": 200, "statusText": "OK"} profile-update.js (라인 44) AJAX 오류 : parsererror : SyntaxError : JSON.parse : 예기치 않은 문자 ' –

+0

이 오류 기능을 제거했으며 데이터베이스가 업데이트되었지만 성공 메시지를받지 못했습니다. –

+0

@echo_Samir 올바른 요소를 선택 했습니까? – element119

관련 문제