使用POST将js变量从iframe发送到php

奥立佛

我正在尝试将变量从js传递到backoffice页面。到目前为止,我已经尝试过使用表单并通过javascript提交表单(但这刷新了页面,这是我不想要的)

  • 我放弃了表单以及何时使用iframe(因此每次提交数据时都不会重新加载页面)。该函数每隔几秒钟运行一次(因此应提交表单):

<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>

  • 但是我的php页面不显示发布的值(我不太确定如何实际获取$ _POST变量):

<?php
$postion = $_POST['location'];
echo $_POST['posSend'];
echo "this is the";
echo $position;
?>

如何获得$_POST变量值?我不能使用$_SESSION-因为这backoffice是一个不同的会话。最好的方法是什么?

编辑我宁愿避免ajax和jquery

MKD

而且我认为您无需为此目的使用表格或iframe。您只想了解用户onf而无需刷新,然后对ajax使用以下方法。

index.html 此中的代码

<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 to location.php
            success: function(data) {
                aler(data);
                // success
            },

            error: function(data) {
                alert("There may an error on uploading. Try again later");
            },

         });  
    });  
    </script>

location.php

echo "position :=".$_POST['pos'];

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章