我遇到了一个错误我的id值没有传递给脚本你能帮我吗?这可能是由于数据造成的:从窗体获取所有数据并以某种方式覆盖ID号码?Jquery ajax数据值没有传递给目标url
var otherPro = $('.euserId').text();
console.log(otherPro);
$.ajax({
type: "POST",
url: "modifyuser.php?id=" + otherPro,
data: $('form.editUser').serialize(),
beforeSend: function() {},
success: function (msg) {
$("#msgholder1").html(msg)
console.log(msg);
},
error: function() {
$("#msgholder1").html("error")
}
});
调试
consol.log#1 51 (index):66 - this is the value of "+ otherPro
php response (var_dump($_POST['id']))
Notice: Undefined index: id in C:\xampp\htdocs\platform\admin\modifyuser.php on line 10
consol.log#2 NULL
php response (if no ID given)
Form
php文件
require_once("../checklogin.php");
require_once("../lib/functions.php");
require_once("../lib/Db.class.php");
// Creates the instance || preg_match('/^(?=.*\d)(?=.*[A-Za-z])[[email protected]#$%]{8,12}$/', $_POST['password'])
$db = new Db();
$user = new users();
$error = array();
var_dump($_POST['id']);
if (empty($_POST['id'])) {
$error[] = 'Brak podanego id';
} else {
$username = $_POST['id'];
}
if (empty($error))
{ // If everything's OK...
$teto = $user->Find($_POST['id']);
if(!empty($teto))
{
$update = $db->query("UPDATE Persons SET username = :username, name =:name, surname = :surname, password = :password, lastlogin = :lastlogin, isOnline = :isOnline, level = :level WHERE id = :id", array(
"id" => $_POST['id'],
"username" => $username,
"name" => $name,
"surname" => $surname,
"password" => $password,
"lastlogin" => '0000-00-00 00:00:00',
"isOnline" => '0',
"level" => $level
));
?>
$(".editUser").hide();
$('#editUser').hide();
var result = '
Modyfikowano wpis.
', //html for main resultdelay = 200, //delay of sub results
data = Array(
'
Polaczenie z baza ','
Modyfikacja wpisu ');
//self executing function starting from array index 0
(function process_els(el_index) {
var el = data[el_index],
precheckUl = $('#precheck ul'),
loadingLi = $('
'),sysPreId = "syspre_"+el_index;
//show loading image
precheckUl.append(loadingLi.clone().attr("id",sysPreId));
//after simulated delay replace loading image with sub check result
setTimeout(function()
{
precheckUl.find('li.loading:first').replaceWith(data[el_index]);
}, delay);
//to simulate the delay recursively call itself until all array elements have been processed
if (el_index + 1 < data.length) {
setTimeout(function() { process_els(el_index + 1); }, delay);
}
else
{
setTimeout(function()
{
//append the final result after all sub checks have been inserted
precheckUl.after(result);
}, (delay*2));
}
})(0);
Modyfikacja wpisu
}else{
echo "
}
} else { //If the "error" array contains error msg , display them.... e.g....
echo '
Bledy w formularzu
foreach ($error as $key => $values) {
echo '' . $values . '
';
}
echo '
}
+0
添加php脚本和html也 –
+0
你可以通过set type来获得 –
+0
发布var_dump($ _ POST)的结果; –