1
I am using Jquery to load an HTML page into a <div>. My code is working correctly, but it’s not passing a value via GET that I need on the other page:
<!DOCTYPE html>
<html>
<head>
<title>Exemplo</title>
<meta charset="utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="js/js_1.9/jquery-1.8.2.js"></script>
<script type="text/javascript" src="js/js_1.9/jquery-ui-1.9.1.custom.min.js"></script>
</head>
<body>
<div id="sidebar">
<ul>
<li><a onclick="carregar('receita.html?cod=1')" href="#">Receita 1</a></li>
<li><a onclick="carregar('receita.html?cod=2')" href="#">Receita 2</a></li>
</ul>
</div>
<div id="conteudo"></div>
</body>
<script>
function carregar(pagina){
$("#conteudo").load(pagina);
}
</script>
</html>
I’m using a page function receita.html that recovers the variable cod
So if I open in the browser receita.html?cod=10 it recovers this variable, but opening the content within the <div> he even opens the page, but does not recover the cod.
Does anyone have any idea how I can fix this?
javascript is correct, the problem seems to be in
receita.html, can you add the part of that file where you use the GET variable? Try addingvar_dump($_GET);exit;at the beginning of the file to see what appears– Pedro Sanção
I did it but nothing happened, I am recovering like this:
function getUrlVars(){
 var vars = [], hash;
 var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
 for(var i = 0; i < hashes.length; i++)
 {
 hash = hashes[i].split('=');
 vars.push(hash[0]);
 vars[hash[0]] = hash[1];
 }
 return vars;
}
var var_cod = getUrlVars()["cod"];If I open the recipe.html page in my browser it works... only inside the other div– Dani Carla
identified the problem, you are searching the GET variables with javascript in
receita.html, but when you call the page with.load('receita.html'), the javascript of the page are not executed– Pedro Sanção
That’s right... and I don’t know how to load them.
hiddenand at the time that load this page pull the values of these fields– Dani Carla