1
I’m having difficulty passing two parameters to a jquery function, where I will receive the location where I clicked, and the place where the content will be exchanged. The reason why I need this, is to make a default function where when I want to change this field to other pages just pass the location that will validate the click. My code is this.
function fnc_conteudo(click, troca){
$(document).ready(function(){
$("a.click").click(function(e){
e.preventDefault();
var href = $(this).attr('href');
$(".troca").load(this.href);
});
});
}
And the call to the code is:
<script type="text/javascript"> $('document').ready(function(){ fnc_conteudo(menu, row); }); </script>
To explain better, I make a request to open a user registration page, soon after will be displayed a "+" button, where I give the possibility to register new users, but I need that when the comrade click on +, he does not open another page and yes in the same place open this page. Then I need also inside this new page, when it clicks saved, I send this file via jquery to the bank.
listarUsuario.php
<script src="js/jquery-1.8.2.min.js" type="text/javascript" ></script> <style> label{ display: block; } .window{ display:none; width:200px; height:300px; position:absolute; left:0; top:0; background:#FFF; z-index:9900; padding:10px; border-radius:10px; } #mascara{ display:none; position:absolute; left:0; top:0; z-index:9000; background-color:#000; } .fechar{display:block; text-align:right;} </style>
<div class = "conteudo">
<div class="container-fluid">
<div align="left" id="inserir">
<button type="button" class="btn btn-default btn-lg">
<a href="#janela1"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Inserir</a>
</button>
</div>
<!-- Listar cargos -->
<legend>Relação de Cargos</legend>
<?php include "listaUsuario2.php";?>
</div>
<!-- Fim listar cargos -->
</div> <!-- FECHA CONTEUDO -->
<div class="window" id="janela1">
<a href="#" class="fechar">X Fechar</a>
<h4>Cadastro de usuario</h4>
<form id="cadUsuario" action="" method="post">
<label>Nome:</label><input type="text" name="TXT_NOMEX_USUAR" id="TXT_NOMEX_USUAR" />
<label>Email:</label><input type="text" name="TXT_ENDER_EMAIL" id="TXT_ENDER_EMAIL" />
<label>Senha:</label> <input type="text" name="TXT_SENHA_USUAR" id="TXT_SENHA_USUAR" />
<br/><br/> <input type="button" value="Salvar" id="salvar" />
</form>
</div>
<div id="mascara"></div>
</div>
</div>
<script type="text/javascript" language="javascript">
$(document).ready(function() { /// Quando usuário clicar em salvar será feito todos os passo abaixo
$('#salvar').click(function() {
var dados = $('#cadUsuario').serialize();
$.ajax({
type: 'POST',
dataType: 'json',
url: 'salvar.php',
async: true,
data: dados,
success: function(response) {
location.reload();
}
});
return false;
});
//// aqui é o script para abrir o nosso pequeno modal
$("a[rel=modal]").click(function(ev) {
ev.preventDefault();
var id = $(this).attr("href");
var alturaTela = $(document).height();
var larguraTela = $(window).width(); //colocando o fundo preto
$('#mascara').css({'width': larguraTela, 'height': alturaTela});
$('#mascara').fadeIn(1000);
$('#mascara').fadeTo("slow", 0.8);
var left = ($(window).width() / 2) - ($(id).width() / 2);
var top = ($(window).height() / 2) - ($(id).height() / 2);
$(id).css({'top': top, 'left': left});
$(id).show(); });
$("#mascara").click(function() {
$(this).hide();
$(".window").hide();
});
$('.fechar').click(function(ev) {
ev.preventDefault();
$("#mascara").hide();
$(".window").hide();
});
});
</script>
main.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>SB Admin 2 - Bootstrap Admin Theme</title>
<!-- Bootstrap Core CSS -->
<link href="../estilos/bootstrap/dist/css/bootstrap.css" rel="stylesheet">
<!-- MetisMenu CSS -->
<link href="../estilos/metisMenu/dist/metisMenu.min.css" rel="stylesheet">
<!-- Timeline CSS -->
<link href="../estilos/css/timeline.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="../estilos/css/sb-admin-2.css" rel="stylesheet">
<!-- Morris Charts CSS -->
<link href="../estilos/morrisjs/morris.css" rel="stylesheet">
<!-- Custom Fonts -->
<link href="../estilos/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="../scripts/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="../scripts/principal00.js"></script>
<script type="text/javascript"> $('document').ready(function(){ fnc_conteudo(); }); </script>
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div id="wrapper">
<!-- Navigation -->
<nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.html">SB Admin v2.0</a>
</div>
<!-- /.navbar-header -->
<ul class="nav navbar-top-links navbar-right">
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
<i class="fa fa-envelope fa-fw"></i> <i class="fa fa-caret-down"></i>
</a>
<ul class="dropdown-menu dropdown-messages">
<li>
<a href="#">
<div>
<strong>John Smith</strong>
<span class="pull-right text-muted">
<em>Yesterday</em>
</span>
</div>
<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque eleifend...</div>
</a>
</li>
<li class="divider"></li>
<li>
<a href="#">
<div>
<strong>John Smith</strong>
<span class="pull-right text-muted">
<em>Yesterday</em>
</span>
</div>
<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque eleifend...</div>
</a>
</li>
<li class="divider"></li>
<li>
<a href="#">
<div>
<strong>John Smith</strong>
<span class="pull-right text-muted">
<em>Yesterday</em>
</span>
</div>
<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque eleifend...</div>
</a>
</li>
<li class="divider"></li>
<li>
<a class="text-center" href="#">
<strong>Read All Messages</strong>
<i class="fa fa-angle-right"></i>
</a>
</li>
</ul>
<!-- /.dropdown-messages -->
</li>
<!-- /.dropdown -->
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
<i class="fa fa-tasks fa-fw"></i> <i class="fa fa-caret-down"></i>
</a>
<ul class="dropdown-menu dropdown-tasks">
<li>
<a href="#">
<div>
<p>
<strong>Task 1</strong>
<span class="pull-right text-muted">40% Complete</span>
</p>
<div class="progress progress-striped active">
<div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width: 40%">
<span class="sr-only">40% Complete (success)</span>
</div>
</div>
</div>
</a>
</li>
<li class="divider"></li>
<li>
<a href="#">
<div>
<p>
<strong>Task 2</strong>
<span class="pull-right text-muted">20% Complete</span>
</p>
<div class="progress progress-striped active">
<div class="progress-bar progress-bar-info" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width: 20%">
<span class="sr-only">20% Complete</span>
</div>
</div>
</div>
</a>
</li>
<li class="divider"></li>
<li>
<a href="#">
<div>
<p>
<strong>Task 3</strong>
<span class="pull-right text-muted">60% Complete</span>
</p>
<div class="progress progress-striped active">
<div class="progress-bar progress-bar-warning" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width: 60%">
<span class="sr-only">60% Complete (warning)</span>
</div>
</div>
</div>
</a>
</li>
<li class="divider"></li>
<li>
<a href="#">
<div>
<p>
<strong>Task 4</strong>
<span class="pull-right text-muted">80% Complete</span>
</p>
<div class="progress progress-striped active">
<div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="80" aria-valuemin="0" aria-valuemax="100" style="width: 80%">
<span class="sr-only">80% Complete (danger)</span>
</div>
</div>
</div>
</a>
</li>
<li class="divider"></li>
<li>
<a class="text-center" href="#">
<strong>See All Tasks</strong>
<i class="fa fa-angle-right"></i>
</a>
</li>
</ul>
<!-- /.dropdown-tasks -->
</li>
<!-- /.dropdown -->
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
<i class="fa fa-bell fa-fw"></i> <i class="fa fa-caret-down"></i>
</a>
<ul class="dropdown-menu dropdown-alerts">
<li>
<a href="#">
<div>
<i class="fa fa-comment fa-fw"></i> New Comment
<span class="pull-right text-muted small">4 minutes ago</span>
</div>
</a>
</li>
<li class="divider"></li>
<li>
<a href="#">
<div>
<i class="fa fa-twitter fa-fw"></i> 3 New Followers
<span class="pull-right text-muted small">12 minutes ago</span>
</div>
</a>
</li>
<li class="divider"></li>
<li>
<a href="#">
<div>
<i class="fa fa-envelope fa-fw"></i> Message Sent
<span class="pull-right text-muted small">4 minutes ago</span>
</div>
</a>
</li>
<li class="divider"></li>
<li>
<a href="#">
<div>
<i class="fa fa-tasks fa-fw"></i> New Task
<span class="pull-right text-muted small">4 minutes ago</span>
</div>
</a>
</li>
<li class="divider"></li>
<li>
<a href="#">
<div>
<i class="fa fa-upload fa-fw"></i> Server Rebooted
<span class="pull-right text-muted small">4 minutes ago</span>
</div>
</a>
</li>
<li class="divider"></li>
<li>
<a class="text-center" href="#">
<strong>See All Alerts</strong>
<i class="fa fa-angle-right"></i>
</a>
</li>
</ul>
<!-- /.dropdown-alerts -->
</li>
<!-- /.dropdown -->
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
<i class="fa fa-user fa-fw"></i> <i class="fa fa-caret-down"></i>
</a>
<ul class="dropdown-menu dropdown-user">
<li><a href="#"><i class="fa fa-user fa-fw"></i> User Profile</a>
</li>
<li><a href="#"><i class="fa fa-gear fa-fw"></i> Settings</a>
</li>
<li class="divider"></li>
<li><a href="login.html"><i class="fa fa-sign-out fa-fw"></i> Logout</a>
</li>
</ul>
<!-- /.dropdown-user -->
</li>
<!-- /.dropdown -->
</ul>
<!-- /.navbar-top-links -->
<div class="navbar-default sidebar" role="navigation">
<div class="sidebar-nav navbar-collapse">
<ul class="nav" id="side-menu">
<li class="sidebar-search">
<div class="input-group custom-search-form">
<input type="text" class="form-control" placeholder="Search...">
<span class="input-group-btn">
<button class="btn btn-default" type="button">
<i class="fa fa-search"></i>
</button>
</span>
</div>
<!-- /input-group -->
</li>
<li>
<a><i class="glyphicon glyphicon-plus"></i> Cadastros<span class="fa arrow"></span></a>
<ul class="nav nav-second-level">
<li>
<a href="listaUsuario.php" class="menu">Usúarios</a>
</li>
</ul>
<!-- /.nav-second-level -->
</li>
</ul>
</div>
<!-- /.sidebar-collapse -->
</div>
<!-- /.navbar-static-side -->
</nav>
<div id="page-wrapper">
<div class="row" id="middle">
AQUI VEM O CONTEUDO DO MEIO
</div
<!-- /.row -->
</div>
<!-- /#page-wrapper -->
<!-- jQuery -->
<script src="../estilos/jquery/dist/jquery.min.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="../estilos/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- Metis Menu Plugin JavaScript -->
<script src="../estilos/metisMenu/dist/metisMenu.min.js"></script>
<!-- Morris Charts JavaScript -->
<script src="../estilos/raphael/raphael-min.js"></script>
<script src="../estilos/morrisjs/morris.min.js"></script>
<script src="../estilos/morris-data.js"></script>
<!-- Custom Theme JavaScript -->
<script src="../estilos/js/sb-admin-2.js"></script>
</body>
</html>
principal00.js
function fnc_conteudo(){
$(document).ready(function(){
$("a.menu").click(function(e){
e.preventDefault();
var href = $(this).attr('href');
$("#middle").load(this.href);
});
});
}
function fnc_Salvar(){
$(document).ready(function(){
$("#salvar").click(function(e){
e.preventDefault();
var href = $(this).attr('href');
$("#middle").load(this.href);
});
});
}
Suggested reading: http://answall.com/questions/6626/comorecrea-um-site-sem-reloade-a-cada-clique-num-link/6634#6634
– Sergio
It did not clear my doubt, because what explains in the post I know how to do, I want something more complete.
– Renan Rodrigues
You can pass the full code so you can see what you have.... jquery and its html....
– Valentim Araújo
I added the part that asked me, but I’m already trying to solve otherwise, that is having a window, where when I press, it comes in display mode:One however, when I’m clicking insert, it does not appear. both methods would help me.
– Renan Rodrigues