If you’re like me, I mean, don’t like jQuery and don’t even use it if I pay you, here’s another way:
<script type="text/javascript" charset="utf-8">
function ajaxObj(meth, url) {
var x;
try {x=new XMLHttpRequest();}
catch(e) {var XmlHttpVersions=new Array("MSXML2.XMLHTTP.6.0", "MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP");for (var i=0; i<XmlHttpVersions.length && !x; i++){try { x=new ActiveXObject(XmlHttpVersions[i]);} catch (e){}}
};
if (!x){displayError("Erro ao criar o objeto XMLHttpRequest.");} else {x.open(meth, url, true);x.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); x.setRequestHeader("Cache-Control", "no-cache");x.setRequestHeader("Pragma", "no-cache");x.setRequestHeader("X-Requested-With", "XMLHttpRequest");return x;}};
function ajaxReturn(x){if(x.readyState==4 && x.status==200){return true;}
}
</script>
<script type="text/javascript" charset="utf-8">
function _(x){ return document.getElementById(x);}
</script>
<script type="text/javascript" charset="utf-8">
function pc(oquepost,pagesc){
if(typeof(oquepost) !== 'undefined'){
var name = oquepost;
}else{
var div1 = document.getElementById('artigo');
var name = div1.getAttribute("data-postid");
};
if(typeof(pagesc) !== 'undefined'){var pagec = pagesc;} else {var pagec = null;};
var vars = 'procuraralgo='+name+'&pagina='+pagec;
var url = "arquivo_procurador.php";
var ajax = ajaxObj("POST",url,true);
ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
ajax.onreadystatechange = function() {
if(ajaxReturn(ajax) == true) {
var return_data = ajax.responseText;
_("artigo").innerHTML = return_data;}
};
ajax.send(vars);
_("artigo").innerHTML = "A processar os dados...";
}
</script>
I hope it helps!
This url "functions/logout.php" is correct ?
– mau humor
yes this correct
– Leonardo Costa
So what’s the problem? Have you tried putting one
alert
in.done
or.fail
to see if the request was able to access the file.– mau humor
Put the whole PHP code. Or this is the whole code. Why if it is, this is the problem.
– mau humor
this and the whole code. that’s a function I want to call the function
logout
that this infunctions/logout.php
when I click on the span with theid click
– Leonardo Costa
First of all you are not calling the function anywhere in the PHP code. Nothing differs a PHP code that runs when it is invoked via browser from a code invoked via AJAX. Therefore, setting a function and never calling it will make it never run. Second, the function is requesting a parameter
$sessao
, which is not being provided by the request and not defined in the code.– mau humor
and hence my question comes where I will call this function with the
ajax
so I asked the question– Leonardo Costa
Let’s go by parts. What is $Session? is the user id? you have it in Javascript?
– mau humor
Where will this $Session parameter come from? It looks like a logout, will need an ajax to make a simple logout?
– Rodrigo Jarouche