0
I have searched a lot and done many tests but I’m not able to send the value of a Javascript variable to a PHP variable.
My case is as follows: I have a real estate portal and I would like to take the information (more precisely the real estate data or just its name) searched by a Javascript function and pass to a variable in PHP, in this case the variable $title, which is the variable that regulates the title that will appear on each page in the browser.
The JS function that picks up this information is this:
function getDadosImobiliaria(id) {
$.getJSON('../site/Control/controlUsuario.php', {type: 'selectDadosImob', imobiliariaId: id}, function(data) {
if (data.tipo == "f") {
var imobiliaria = data.nome+" "+data.sobrenome;
$('.nomeAnunciante').html(imobiliaria);
} else {
var imobiliaria = data.sobrenome;
$('.nomeAnunciante').html(imobiliaria);
}
$('#logoAnunciante').attr('src', 'imagensUpload/'+data.logo);
$('.ruaNumero').html(data.rua+', '+data.numero);
$('.bairro').html(data.bairro);
$('.cidadeUf').html(data.cidade+' - '+data.uf);
$('#fone').html(data.fone);
$('.showCidade').html(data.cidade);
$('.showCidade').attr('href', '/imobiliarias/'+data.cidade);
$('.countTotalImoveis').html(data.count);
if (data.creci != undefined) {
$('.creci').html("CRECI: "+data.creci);
}
});
}
How can I pass the real estate variable or any other variable to the PHP variable $title contained in another archive and thus form the titles of the pages of the real estate portal? By POST? Ajax?
Thanks in advance!
The only objective is to change the title?
– Andrei Coelho
Post php page code as well. You can help find the solution.
– Andrei Coelho
But if you just change the title use the famous... Document.title = "title"
– Andrei Coelho
Possible duplicate of Pass Javascript variable to PHP body
– Pedro Augusto
Andrei, the only goal is to change the title. It needs to be dynamic to improve the SEO of pages. And the PHP code practically does not have, I tested only with the variable $title receiving the value. Since I’m not really in the programming area, I couldn’t go on. I used Document.title after seeing what you suggested, but it didn’t work either. I just want to be able to pass this JS variable to PHP. Thanks in advance!
– Alessandro Beiersdorf
The variable
imobiliariais the value you want it to contain in<title>?– Andrei Coelho
But do you want to send it to PHP or take it via ajax and inject it into <title> with JS? Your question is very confusing, edit it and explain what you really want.
– Guilherme Nascimento
Yes Andrei, the real estate variable is the value I want to pass to the title.
– Alessandro Beiersdorf
Guilherme, I wanted to or send by PHP, either way (ajax, post and everything possible) or, by JS even, set the title with the variable real estate. I managed to do this after a lot of testing, but unfortunately, setting by JS the title of the page, does not appear the title I did by JS when searching on google, IE, It is not relevant to set by JS the SEO of the page. Then I will have to do by PHP to have relevance.
– Alessandro Beiersdorf