我正在尝试将变量从js传递到backoffice
页面。到目前为止,我已经尝试过使用表单并通过javascript提交表单(但这刷新了页面,这是我不想要的)
<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
$postion = $_POST['location'];
echo $_POST['posSend'];
echo "this is the";
echo $position;
?>
$.post
按照这里的建议尝试使用$.post
发送JS变量,但这也不起作用。如何获得$_POST
变量值?我不能使用$_SESSION
-因为这backoffice
是一个不同的会话。最好的方法是什么?
编辑我宁愿避免ajax和jquery
而且我认为您无需为此目的使用表格或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] 删除。
我来说两句