幫助!所有字段未定義的值ajax JQuery php
function UpdateData(){
var id = $('#id').attr('value');
var name = $('#name').attr('value');
var department = $('#departament').attr('value');
var phone = $('#phone').attr('value');
var mail = $('#mail').attr('value');
$.ajax({
url: 'updatePersonal.php',
type: "POST",
data: "submit=&name="+name+"&department="+department+"&phone="+phone+"&mail="+mail+"&id="+id,
success: function(datos){
alert(datos);
consultingData();
$("#form").hide();
$("#table").show();
}
});
return false;}
當我調用該函數不起作用 不定值,存儲在數據庫中的值是不確定的各個領域,我試圖解決它通過添加{}對數據串: - >
data: {"submit=&name="+name+"&department="+department+"&phone="+phone+"&mail="+mail+"&id="+id},
,但如果我這樣做,不執行下一部分
success: function(datos){
alert(datos);
consultingData();
$("#form").hide();
$("#table").show();
}
updatePersonal .PHP - >
<?php
require('functions.php');
if(isset($_POST['submit'])){
require('clases/personal.class.php');
$objPersonal = new Personal;
$id = htmlspecialchars(trim($_POST['id']));
$name = htmlspecialchars(trim($_POST['name']));
$department = htmlspecialchars(trim($_POST['department']));
$phone = htmlspecialchars(trim($_POST['phone']));
$mail = htmlspecialchars(trim($_POST['mail']));
if ($objPersonal->actualizar(array($name,$department,$phone,$mail),$id) == true){
echo 'Saved';
}else{
echo 'There was an error...';
}
}else{
if(isset($_GET['id'])){
require('clases/personal.class.php');
$objPersonal = new Personal;
$consult = $objPersonal->show_person($_GET['id']);
$personal = mysql_fetch_array($consult);
?>
<form method="post" action="updatePersonal.php" onsubmit="UpdateData(); return false">
<input type="hidden" name="id" id="id" value="<?php echo $personal['id']?>" />
<p>
<label>Name<br />
<input class="text" type="text" name="name" id="name" value="<?php echo $personal['name']?>" />
</label>
</p>
<p>
<label>Department<br />
<input class="text" type="text" name="department" id="department" value="<?php echo $personal['department']?>" />
</label>
</p>
<p>
<label>Phone<br />
<input class="text" type="text" name="phone" id="phone" value="<?php echo $personal['phone']?>" />
</label>
</p>
<p>
<label>Mail<br />
<input class="text" type="text" name="mail" id="mail" value="<?php echo $personal['mail']?>" />
</label>
</p>
<p>
<input type="submit" name="submit" id="button" value="Send" />
<label></label>
<input type="button" name="cancel" id="cancel" value="Cancel" onclick="Cancel()" />
</p>
</form>
<?php
}
}
?>
向我們展示您的'updatePersonal.php'文件... – algorhythm 2014-09-22 19:47:15
ProTip:使用.val()而不是'.attr('value')'。 – 2014-09-22 19:57:55
data:{「submit =&name =」+ name +「&department =」+ department +「&phone =」+ phone +「&mail =」+ mail +「&id =」+ id}'是無效的JavaScript語法。 – 2014-09-22 19:58:29