Reputation: 11
i want to pass js variable to php .my code is follows
function sub(uid){
window.location.href='<?php echo $urlp -> certificationceap(uid) ;?>';
here is some problem
Upvotes: 0
Views: 237
Reputation: 1091
You can use ajax to achieve this..... advance apologies if it is not intended answer...
function send_var(js_var_1, js_var_2){
var parms = 'js_var_1='+js_var_1+'&js_var_2='+js_var_2;
if(js_var_1!='' && js_var_1!=''){
if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
//your result in xmlhttp.responseText;
}
}
xmlhttp.open("POST","<REMOTE PHP SCRIPT URL>",true);
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlhttp.send(parms);
}
}
Upvotes: 0
Reputation: 943142
You can't.
At this stage, it is too late to send data to the PHP program as it has finished executing.
You need to make a new HTTP request to get data back to it.
Probably something along the lines of:
function sub(uid){
location.href = 'redirect.php?uid=' + encodeURIComponent(uid);
}
Upvotes: 1