View Full Version : Javascript var to php

04-22-2011, 01:16 AM

I was creating AJAX script for my website and it works fine :)

But then I faced problem. My AJAX output function is below:

function setOutput(){
if(httpObject.readyState == 4){
var answer = eval('(' + httpObject.responseText + ')');
document.getElementById('vardas2').innerHTML = answer[0];
document.getElementById('pavarde2').innerHTML = answer[1];
document.getElementById('emailas2').innerHTML = answer[2];
document.getElementById('reemailas2').innerHTML = answer[3];
document.getElementById('slaptazodis2').innerHTML = answer[4];
document.getElementById('reslaptazodis2').innerHTML = answer[5];
document.getElementById('date2').innerHTML = answer[6];


I want to get use of variable answer[0] in my php script.

How I can do it?

Btw, I tried to use:

$java_vardas = $_POST['vardas2'];
echo $java_vardas;

but it does not work...

Please help me with this.
Kind regards, auriaks.

04-22-2011, 01:52 AM
PHP is loaded first it can't be used with javascript directly. What function are you trying to use it sometimes is easier to just do it all in JS?