I know is a silly question but I thought I should ask since you guys know more about postgresql. Sorry for being analytical, but I think its the only way to make my question clear.

I'm using postgresql 9.1 /postGIS 2.0 /openlayers/geoserver and apache

I've managed to get a feature's fid when clicked from a vector layer. I edited it using javascript and kept only the number, for example 64.

Then I set this as a value of a hidden html form. Using ajax I m trying to pass this value to a PHP value and perform a query. Openlayers, javascript and ajax work fine but php never gets the value. Here is my code

            function selected_feature(event){
var sf = event.feature.fid;
    var sfs = sf.split(".");
    //that's the number out of fid
    var sff = sfs[1];
    //feed it to the form
    //alert it-works
    //call ajax

    <!--the form-->
    <form id="hifo" name="hifo" method="post">
    <input type="hidden" id="blahhh" name="blahhh" />

    //outside openlayers code
            function loadXMLDoc(){
        var xmlhttp2;
        var t2lFname=document.getElementById("blahhh").value;
        var parb="blahhh="+t2lFname;

        if (window.XMLHttpRequest)
          {// code for IE7+, Firefox, Chrome, Opera, Safari
          xmlhttp2=new XMLHttpRequest();
          {// code for IE6, IE5
          xmlhttp2=new ActiveXObject("Microsoft.XMLHTTP");
        xmlhttp2.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

          if (xmlhttp2.readyState==4 && xmlhttp2.status==200)

//and then php
$blah = $_POST['parb']; 
echo $blah;
 //fetching to fill array
 $resultd=pg_query($conn, $queryd);
        echo $arrayd['p_name'];
                echo $arrayd[$d];
        echo $d;

So basically use the fid as an id, via ajax to query the db. All this code is in the same file (named map.php).Problem is php's echos not working and query not working at all. I ve searched the web, I red tutorials and still no luck. Everything works except php. What should I do? Please advise


PS I also tried OpenLayers.Request, found here and still no luck

  • 1
    do you know for sure that the value is sent? Get Fiddler running and check that your request is indeed a POST and that the value you expect is being passed. Also do you know for sure that the correct PHP script is being called? Change the PHP script to always echo 'something' and check that this gets back to the browser. These kinds of simple steps will turn your big ambiguous problem into one or two small and well-defined problems. – tomfumb Feb 6 '13 at 2:11
  • Agree with Tomfumb's suggestion: at first create PHP file that contains only echo "foo"; so you can determine, whether problem is in your PHP code, or in JavaScript AJAX call. If it works, continue with var_dump $_REQUEST; Also, I would suggest using OpenLayers.Request or jQuery's AJAX functions. Oh, and most important thing: examine request in Firebug. – user1702401 Feb 6 '13 at 7:28
  • @tomfumb @user1702401 Thanks for the advise. I also tried jquery and (guess) still no luck. I added an echo'test'; before my query and gets rendered. I believe the biggest problem is that I'm new to ajax/jquery and I havent found a tutorial about passing values in the same file. So I'm kind of voodoo-coding here. You guys know a good tutorial or can you give me some guidelines or something? Thanks – slevin Feb 7 '13 at 0:54
  • it being the same file makes no difference, you're still just dealing with client requesting from server over HTTP. Did you use Fiddler or another network debugger? You need to first verify that your request is being sent and that the POST body is what you expect. Fiddler has plenty of tutorials – tomfumb Feb 8 '13 at 21:56
  • @tomfumb I edited my code according to this simle tutorial. Works fine. But, one more thing. Now I want to do something like jQuery.post("testone.php", { jas : sff }, function(data) { //pass data to php var });} Thanks again.... – slevin Feb 8 '13 at 23:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.