php怎么获取js值 phpjsmysql 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以采用ajax或者是采用隐藏域来进行表单提交。 js的数据是需要提交给php才可以被php获取的。你这样写,$aa只是一个字符串。并不会执行javascript获取到值。需要这样改:client.html<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <meta http-equiv="conent-type" content="text/html; charset=utf-8"> <title> client post</title> <script src="//code.jquery.com/jquery-1.11.0.min.js"></script> </head> <body><script type="text/javascript"> $(document).ready(function(){ navigator.geolocation.getCurrentPosition(showPosition); }) function showPosition(position){ loc=position.coords.latitude+','+position.coords.longitude; $.post("server.php", { loc: loc },function(ret){ if(ret.success==true){ alert('success'); }else{ alert('fail'); } },'json'); }</script> </body></html>server.php<?php$loc = isset($_POST['loc'])? $_POST['loc'] : '';$con = mysql_connect("localhost","root","root");if (!$con){ die('Could not connect: ' . mysql_error());}mysql_select_db("qiye_wx", $con);mysql_query("INSERT INTO qianru (loc) VALUES ('$loc')");mysql_close($con);$ret = array();$ret['success'] = true;echo json_encode($ret);?> 3楼你好:我是只想在一个php文件里面执行完成,不是要在另外的html页面完成。 ajax PHP 不能和JS 不能同时执行。 不行的,你獲取loc必須以html運行。之後傳給 php入庫。但靠 php是獲取不到loc的。 请教关于php中使用ajax实现菜单联动查询的思路和方法 求一个php正则表达 PHP代码表达的意思? ### Apache 处理 NOT FOUND等问题 关于登录后跳转的问题 急急急!!!!!关程序报错的问题!!!求助!!!!!谢谢! 使用PHP程序开发高效的WEB网络系统 PHP多层require问题,请php高手指教! 新学PHP,请教关于session在PHP中的配置问题 include问题 利用JoomFish进行多语言网站设计,需要什么前期工作。求大神指点 php做为接口返回数据问题
client.html<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="conent-type" content="text/html; charset=utf-8">
<title> client post</title>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
</head> <body><script type="text/javascript">
$(document).ready(function(){
navigator.geolocation.getCurrentPosition(showPosition);
})
function showPosition(position){
loc=position.coords.latitude+','+position.coords.longitude;
$.post("server.php", { loc: loc },function(ret){
if(ret.success==true){
alert('success');
}else{
alert('fail');
}
},'json');
}</script>
</body>
</html>
server.php<?php
$loc = isset($_POST['loc'])? $_POST['loc'] : '';$con = mysql_connect("localhost","root","root");
if (!$con){
die('Could not connect: ' . mysql_error());
}
mysql_select_db("qiye_wx", $con);mysql_query("INSERT INTO qianru (loc) VALUES ('$loc')");
mysql_close($con);$ret = array();
$ret['success'] = true;echo json_encode($ret);
?>
不行的,你獲取loc必須以html運行。之後傳給 php入庫。
但靠 php是獲取不到loc的。