I need your advise. I'm new to ajax and jquery. I'm using postgresql 9.1 /postGIS 2.0 /openlayers/geoserver and apache.
我需要你的建议。我是ajax和jquery的新手。我正在使用postgresql 9.1 / postGIS 2.0 / openlayers / geoserver和apache。
I managed getting a feature's id when clicked on the map (openlayers), using javascript.
我在使用javascript点击地图(openlayers)时设法获得了一个功能ID。
Using ajax I m trying to pass this value to a PHP value and perform a query. Openlayers, jquery, javascript and ajax work fine but php never gets the value. Here is my code snippets.
使用ajax我试图将此值传递给PHP值并执行查询。 Openlayers,jquery,javascript和ajax工作正常,但php永远不会获得价值。这是我的代码片段。
//this is inside openlayers init function
function selected_feature(event){
//getting the id
var sf = event.feature.fid;
var sfs = sf.split(".");
var sff = sfs[1]
//ajax
$(document).ready(function()
{
$.post("map.php", { jas: 'sff'});
});
//the php code snippet, after openlayers
$_SESSION['blah'] = $_POST['jas'];
$blah= $_SESSION['blah'];
echo $blah;
$queryd='
SELECT
pins.p_name
FROM
pins
WHERE
pins.p_id='.$blah;
//fetching to fill array
$resultd=pg_query($conn, $queryd);
$nord=pg_num_rows($resultd);
$d=0;
while($arrayd=pg_fetch_array($resultd)){
$name[$d]=$arrayd['p_name'];
$d++;
echo $arrayd['p_name'];
echo $arrayd[$d];
}
Problem is php's echos not working and query not working at all. I know this question sounds like a dublicate but I believe is different because all the code is in the same file (named map.php). Plus, there is some web-mapping on the background. I dont even know if one of the web-mapping programms causing the problem.
问题是php的回声不起作用,查询根本不起作用。我知道这个问题听起来像一个dublicate,但我相信是不同的,因为所有的代码都在同一个文件中(名为map.php)。此外,背景上还有一些网络映射。我甚至不知道是否有一个导致问题的网络映射程序。
Please advise
Thank you.
EDIT I just edited the ajax part. I've replaced with this
编辑我刚刚编辑了ajax部分。我已经用这个替换了
jQuery.post("map.php", { jas : "sff" }, function(data) {
// alert(data);
});
...still no luck
......还是没有运气
EDIT #2
According to this tutorial I edited my code. So now I have this jquery in my map.php
根据这个教程,我编辑了我的代码。所以现在我在map.php中有这个jquery
jQuery.post("testone.php", { jas : sff }, function(data) {
alert(data);
});
And in the testone.php this php code
并在testone.php这个PHP代码
<?php
$jas = $_POST['jas'];
print $jas;
?>
map.php actually alerts the data. But, one more thing. How to pass the data back to map.php as an PHP value, so I can also activate the query? Most tutorials out there are about alerting the data or put them in a <div>
. I want to use php. Something like
map.php实际上会警告数据。但是,还有一件事。如何将数据作为PHP值传递回map.php,这样我也可以激活查询?大多数教程都是关于提醒数据或将它们放在
jQuery.post("testone.php", { jas : sff }, function(data) {
//put returned data in a php var
});
1 个解决方案
#1
0
I'd move your PHP to another file and then you'll need to echo json_encode($name);
and handle your returned data within a callback handler on your jQuery post.
我将你的PHP移动到另一个文件,然后你需要回显json_encode($ name);并在jQuery帖子的回调处理程序中处理返回的数据。
$.post('new.php',{jas:'sff'},function(data){ //do something cool with data[0] through the last index of the array });
$ .post('new.php',{jas:'sff'},function(data){//用数据[0]通过数组的最后一个索引做一些很酷的事情});
#1
0
I'd move your PHP to another file and then you'll need to echo json_encode($name);
and handle your returned data within a callback handler on your jQuery post.
我将你的PHP移动到另一个文件,然后你需要回显json_encode($ name);并在jQuery帖子的回调处理程序中处理返回的数据。
$.post('new.php',{jas:'sff'},function(data){ //do something cool with data[0] through the last index of the array });
$ .post('new.php',{jas:'sff'},function(data){//用数据[0]通过数组的最后一个索引做一些很酷的事情});