javascript - using POST to send js variable to php from iframe -
i trying pass variable js backoffice
page. far i've tried using form , submitting javascript (but refreshes page, don't want)
- i ditched form , when iframe (so page doesn't reload everytime data submitted). function run every few seconds (so form should submitting):
<iframe style="visibility:hidden;display:none" action="location.php" method="post" name="location" id="location"> <script> /*some other stuff*/ var possend = document.getelementbyid("location"); possend.value = pos; possend.form.submit(); </script>
- however php page not display value posted (im not quite sure how $_post variable):
<?php $postion = $_post['location']; echo $_post['possend']; echo "this the"; echo $position; ?>
- i tried
$.post
suggested here using$.post
send js variables didn't work either.
how $_post
variable value? cannot use $_session
- backoffice
different session. best method this?
edit i'd rather avoid ajax , jquery
and think no need use form or iframe purpose . want know user onf without refreshing use following method ajax.
index.html
code in will
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script> <script> navigator.geolocation.getcurrentposition(function(position) { pos = new google.maps.latlng(position.coords.latitude,position.coords.longitude); $.ajax( { url:'location.php', type: 'post', datatype: 'json', data: {'pos':pos}, // post location.php success: function(data) { aler(data); // success }, error: function(data) { alert("there may error on uploading. try again later"); }, }); }); </script>
location.php
echo "position :=".$_post['pos'];
Comments
Post a Comment