Ryler Sexton
Ryler Sexton

Reputation: 153

Ajax return value using with PHP

Hi I'm having some problems making my function structure. Would appreciate any help.

First this function should delete map markers once OnChange event is triggered from index.php. And send post values to xmlmapquery.php for data retrieval. once retrieved, The data should be stored back to my index.php in <div id='content'>

function filter()
{ 
   for (var i = 0; i < markersArray.length; i++ ) {
      markersArray[i].setMap(null);
   }
   markersArray.length = 0;

   var lgu = $('#lgu').val();
   var category = $('#category').val();
   var type = $('#type').val();
   $.get('xmlmapquery.php', { filter: lgu, filter2: category, filter3: type},function(data){
        $('#content').text(data);
   )};
};

Now this is xmlmapquery.php

<?php  
  include('connection_db.php');
  // Start XML file, create parent node
  $dom = new DOMDocument("1.0");
  $node = $dom->createElement("markers");
  $parnode = $dom->appendChild($node); 

  if(isset($_POST['filter']) && isset($_POST['filter2']) && isset($_POST['filter3'])){
     $query = "SELECT * FROM markers WHERE type='".$_POST['filter']."' and type='".$_POST['filter2']."'
                                        and type='".$_POST['filter3']."'";
  } 
  // Select all the rows in the markers table
  $result = mysql_query($query);
  if (!$result) {  
     die('Invalid query: ' . mysql_error());
  } 

  header("Content-type: text/xml"); 

  // Iterate through the rows, adding XML nodes for each
  while ($row = @mysql_fetch_assoc($result)){  
    // ADD TO XML DOCUMENT NODE  
    $node = $dom->createElement("marker");  
    $newnode = $parnode->appendChild($node);   
    $newnode->setAttribute("name",$row['name']);
    $newnode->setAttribute("address", $row['address']);  
    $newnode->setAttribute("lat", $row['lat']);  
    $newnode->setAttribute("lng", $row['lng']);  
    $newnode->setAttribute("type", $row['type']);
  } 
  echo $dom->saveXML();
?>

Would appreciate help on this. currently the function is NOT working even deleting the markers is not working. Once i get this thing working I will add more commands to the function that would get data and create new markers for my map. Thanks in advance.

Upvotes: 0

Views: 317

Answers (1)

Filippo oretti
Filippo oretti

Reputation: 49817

Suppose your script logic is ok, and no die() or other php methods are returning null or false (anyway you should see in your browser console).

Things to do are:

1 - check firebug/chrome/browser console when launching request (if the request is hidden in some way use the "save" request method in console to check that)

2 - use var_dump($dom->saveXML()); instead of echo $dom->saveXML();

3 - check server/php logs when possible

4 - be sure your request uirl is complete and working and i'm referring to $.get('xmlmapquery.php');

if you follow this line of debugging, unless ghosts doesn't exists, you will be able to run your script easly.

Hope it will help

Upvotes: 2

Related Questions