我有一个需要 POST 数据才能获得 ajax 响应的页面。依赖 POST 数据的信息显示正常。但是,在那之后,如果用户想要更新一些显示的数据,我想再进行一次 ajax 调用来即时更新它。然后问题来了,因为第一个脚本没有从用户请求更新信息的页面中获取任何 POST 数据。
现在我有这个,这显然给我带来了问题
$(document).ready(function(){
var uid = <?php echo $_POST['user_id']; ?>;
$.ajax({
type: "POST",
data : {user_id:uid},
cache: false,
url:"modules/user/showuserdata.php",
success : function (data) {
$("#response").html(data);
}
})
});
$('#commit-changes').click(function(){
$('#commit-user').submit();
$.ajax({
type: "POST",
data: $("#commit-user").serialize(),
cache: false,
url:"modules/user/updateuser.php",
success : function(data){
$("#response-update").html(data);
}
})
});
chrome输出的javascript错误是
$(document).ready(function(){
var uid = <br />
Uncaught SyntaxError: Unexpected token <
<b>Notice</b>: Undefined index: user_id in <b>C:\xampp\htdocs\inacesso\admin\edituser.php</b> on line <b>73</b><br />
;
为了更好地阅读,我省略了 html,但如有必要,请注意我。
关于如何绕过这个的任何提示?我不想使用 SESSION 变量...
很高兴我能在这方面得到所有帮助。
编辑
showuserdata.php 的 HTML 响应
$user = 新用户();
$id = $_POST['user_id'];
$rcs_user = $user->getUserByID($id);
$rcs_roles = $user->getRoles();
$role ='';
foreach($rcs_roles as $roles)
{
if($roles->role_number == $rcs_user->permissao)
$role .= '<option value="'.$roles->role_number.'" selected="selected">'.$roles->role.'</option>';
else
$role.= '<option value="'.$roles->role_number.'">'.$roles->role.'</option>';
}
if($rcs_user->activo == 0)
{
$activo = '<input type="checkbox" name="activo" class="on_off_checkbox" value="1" />';
}
else
{
$activo = '<input type="checkbox" name="activo" class="on_off_checkbox" checked="checked" value="1" />';
}
$response = '';
$response.='<form id="validation commit-user" action="" method="post">
<fieldset >
<input type="hidden" name="user_id" value="'.$_POST['user_id'].'"/>
<legend>Actualizar Dados Utilizador</legend>
<div class="section ">
<label>Nome<small>Insira o seu nome</small></label>
<div>
<input type="text" class="validate[required,custom[onlyLetterSp]] large" name="nome" id="f_required" value="'.utf8_encode($rcs_user->nome).'">
</div>
</div>';
$response.='<div class="section ">
<label> Email<small>Insira o seu email</small></label>
<div>
<input type="text" class="validate[required,custom[email]] large" name="email" id="e_required" value="'. utf8_encode($rcs_user->email).'">
</div>
</div>';
$response.= '<div class="section">
<label>Permissões<small>Seleccione o tipo de utilizador </small></label>
<div>
<select class="medium" name="role">
'.$role.'
</select>
</div>
</div>
<div class="section">
<label>Activo<small>Activar utilizador</small></label>
<div>
'.$activo.'
<span class="f_help">ON / OFF </span>
</div>
</div>
<div class="section last">
<div>
<a href="" id="commit-changes" class="uibutton submit_form" name="submit">Submeter</a><a class="uibutton special" onClick="ResetForm()" title="Limpar Formulário" >Limpar Formulário</a>
</div>
</div>
</fieldset></form>';
echo $response;