I have a call of an ajax function and I want send a var like:
<a href="next.php" onclick="sendajax()">reload</a>
from my php page for send this with ajax function POST:
<script>
function sendajax(){
var xmlObj=new XMLHttpRequest();
xmlObj.open("POST","miscript.php", true);
xmlObj.setRequestHeader("content-type","application/x-www-form-urlencoded");
xmlObj.onreadystatechange = function(){
if(xmlObj.readyState == 4 && xmlObj.status == 200){
document.getElementById("response").innerHTML = xmlObj.responseText;
}
}
xmlObj.send('name=Status');
}
</script>
How can I add this var to send like?:
function sendajax(myVar){
....
xmlObj.send(myVar);
I'm trying add this, but only send text.
Thanks!
EDIT I think that my question ins't duplicate, because I want send vars from the link clicked, not write this into var like:
var params = "lorem=ipsum&name=binny";
I know how to write this and pass this, I ask: how to send this var to function and add/concatenate this into string. Without use form.. Thanks!!!!!!!