Monday 15 September 2014

How to pass a value from JavaScript in php? -



How to pass a value from JavaScript in php? -

translate translator google. did not swear if not clear. russia.

the question arose. how pass value of alert in javascript in variable $ value in php, , write in case file. , question: how hide alert? or utilize instead visually not visible, value passed?

//a lot of code { console.log(data); alert(data['value']); } });

so. there php script writes logs (current page , previous one) file. according principle here:

//a lot of code $home = $_server['http_host'] . $_server['request_uri']; $referer = $_server['http_referer']; $value = how value of java script convey here?; $lines = file($file); while(count($lines) > $sum) array_shift($lines); $lines[] = $home."|".$referer."|".$value."|\r\n"; file_put_contents($file, $lines);

it necessary value of js transferred php-script , write file. how it? prompt please. novice in of this.

php scripts run before javascript, means can pass php variables javascript, not other way around. however, can create ajax post request javascript php script, , grab post info in php through global $_post variable.

assuming utilize jquery, javascript like:

// assign info object: var info = { value: "test" }; // send php script via ajax post request: $.ajax({ type: "post", url: "http://your-site-url/script.php", data: info });

and php script like:

// if value received, assign it: if(isset($_post['value'])) $value = $_post['value']; else // else;

javascript php jquery json

No comments:

Post a Comment