1
My question is whether this code of mine is correct.
$(document).ready(function(){
$("#fechar").click(function(e){
e.preventDefault();
String lista_Cont = $(this).attr('<?php include "listaUsuario2.php";?>');
$("#lista").load(this.lista_Cont);
});
});
The function of it is, when I close the modal, where I used to register a new user, it reload the updated content again, however is on the same page where already this.
I have an Admin page, where I click to register and go to users, the system in Ajax returns only the content of the changed medium, in this content comes the code where I list all users already registered and give the option to register new user, if chosen, this option opens a modal, where I register new User, however this modal remains open, and when I close it, the page is not updated. I need that when I close it already update the section to min, and enable me to see new users registered immediately.
MY COMPLETE CODE:
<script type="text/javascript">
$(document).ready(function(){
$("#fechar").click(function(e){
e.preventDefault();
String lista_Cont = $(this).attr('<?php include "listaUsuario2.php";?>');
$("#lista").load(this.lista_Cont);
});
});
jQuery(document).ready(function(){
jQuery('#cadUsuario').submit(function(){
var dados = jQuery( this ).serialize();
jQuery.ajax({
type: "POST",
url: "salvarUsuario.php",
data: dados,
success: function( data )
{
alert( data );
}
});
return false;
});
});
</script>
<div class = "conteudo">
<div class="container-fluid">
<div align="left" id="inserir">
<button type="button" class="btn btn-default btn-lg" data-toggle="modal" data-target="#myModal">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Inserir
</button>
</div>
<!-- Listar Usuarios -->
<legend>Úsuarios Cadastrados</legend>
<div id="lista">
<?php include "listaUsuario2.php";?>
</div>
</div>
<!-- Fim listar Usuarios -->
</div> <!-- FECHA CONTEUDO -->
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Novo Úsuario</h4>
</div>
<div class="modal-body">
<div align="center">
<form class="form-horizontal" action="" method="post" id="cadUsuario">
<fieldset>
<!-- Text input-->
<div class="control-group">
<label class="control-label" for="TXT_NOMEX_USUAR"></label>
<div class="controls">
<input id="TXT_NOMEX_USUAR" name="TXT_NOMEX_USUAR" type="text" placeholder="Nome" class="input-large">
</div>
</div>
<!-- Text input-->
<div class="control-group">
<label class="control-label" for="TXT_ENDER_EMAIL"></label>
<div class="controls">
<input id="TXT_ENDER_EMAIL" name="TXT_ENDER_EMAIL" type="text" placeholder="Email" class="input-xlarge">
</div>
</div>
<!-- Password input-->
<div class="control-group">
<label class="control-label" for="TXT_SENHA_USUAR"></label>
<div class="controls">
<input id="TXT_SENHA_USUAR" name="TXT_SENHA_USUAR" type="password" placeholder="Senha" class="input-small">
</div>
</div>
<br>
<br>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal" id="fechar">Fechar</button>
<button type="submit" class="btn btn-primary" id="botao_cadUsuario">Salvar</button>
</div>
</fieldset>
</form>
</div>
</div>
</div>
</div>
</div>
Just like, I want to do it in a way that only uses ajax, and it loads this same page
– Renan Rodrigues
It may be the same. As long as it is identical to your formatting. But it does not need the include. The load already loads the page.
– Diego Souza
He will carry the same thing inside my main ? Because this page is already inside a main one, and if I upgrade it goes back to home from the main one.
– Renan Rodrigues
Oh Bro. You have a Div#List. Okay? Inside this Div you carry a Include for what I see. It’s the Users list. Beauty. When you register someone new and close the modal you want to reload this list with the new list with the new registered user. Right ? Then, you can use the same Include page. Put it on Load. And put a cache:false in Ajax.
– Diego Souza
Better yet, Dude. Put in your ajax a Success.
– Diego Souza
how would this look ?
– Renan Rodrigues
I edited my Code.
– Diego Souza
Thank you, get success with your help. Now I would like you to help me in the delete part. has like ?
– Renan Rodrigues
Yes. Try something and tell us. Maybe even a new guy.
– Diego Souza
http://answall.com/questions/67212/delete-no-banco-utilizando-ajax-e-jquery The link to my other question.
– Renan Rodrigues