How do I go about passing data from JavaScript code to PHP and back.
Right now, I do this is a round about way:
PHP to JavaScript:
I would simply use the inline echo to send the data:
<script type="text/javascript">
var data = <? echo $target_variable ?>
</script>
VEYA
<script type="text/javascript">
var data = <?= $target_variable ?>
</script>
JavaScript to PHP: I would create a form element in the JavaScript that would sumbit the data for me to the php file:
<script type="text/javascript">
var data = targetData;
document.write("
<form method=\"post\">
<input type=\"hidden\" value=\""+target_value+\""></input>
</form>
");
</script>
</script>
Bunu yapmak için daha iyi bir yolu var mı? Şey iyi uygulamalar tür.