1

私は現在、フォームを送信する ajax に問題があり、エラーがどこにあるかを見つけることができませんでした。

ここに私の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();" />

これは私のjavascriptです:

    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

ありがとう!。

4

2 に答える 2

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;
 }
于 2013-06-22T00:54:25.947 に答える