AJAX giving out of memory error

AJAX giving out of memory error

Hi,

I don't know what is wrong here, the PHP or the call to AJAX.

error is: uncaught exception: out of memory

I suspect AJAX because the .php file populates the database properly.

Here is my code with pertinent notes in bold.

Thanks in advance for help in solving this.

R.

HTML CODE:

  1. <!DOCTYPE html>

    <!-- Comments about the program -->

    <html>

    <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
       
    <title> GPS Information from Garman GPSmap76CSx </title>

    <!-- ============== styles  ================ -->

    <link rel="stylesheet " type="text/css" href="css/gps.css" />

    <!-- ============== scripts1 ================ -->

        <script  type="text/javascript" src="../jquery/jquery-1.9.1.js"></script>   

    <body>

    <!-- =============== html  ================== -->

    <div class="wrapper">
              
    <div id="forms">

             <form name="gps" id="gps" action="#">
                  <p>To Down load a Garman GPX file directly to 'mymapping' database file.</p>
      
                    <p> <label for='gpxname'>Enter GPX File Name</label>
                   <input type="text" style="width:170px" class='hov'  name='gpxname' id='gpxname'/><br>
                      
                     </p>
               </form>
       
    </div>
    </div>

    <div id="rbox" >


    </div>

    <!-- =============== scripts2 ================ -->

    <script type="text/javascript">

    $('#gpxname').change(function ()  {
        var filename=$('#gpxname').val();

         myAjaxCall(filename) });
                   
    </script>

    <!-- ============  Function showTable  =================== -->

    <script type="text/javascript">

    function showTable(wptdata) {

  2. alert("wpt3 "+wptdata[2]['name']); // Nothing Shows Up.

    }

    </script>

    <script type="text/javascript">

    <!-- ============  Function myAjaxCall  =================== -->

    function myAjaxCall(gpxfile) {

    var request = $.ajax({
        url: "error-downloadGpx.php",
        type: "GET",
        data: {"gpxfile":gpxfile},
        dataType: "json",       
    });
          //request.done(showTable); // detailed error: uncaught exception: out of memory
         
        request.done(alert("data back "+data[0]['name']));  // nothing shows up
           
    request.fail(function( jqXHR, textStatus ) {
      alert("Request failed, see firebug."); //document.write( "Request failed: " + textStatus );  
    });


    }// myAjaxCall

    </script>

    </body>
    </html>

PHP Code:


  1. <?php

    header('Content-Type: application/json'); // so JSON is returned properly

    set_include_path( '../include' );
    error_reporting (E_ALL ^ E_NOTICE);

       $hostname='localhost';
       $username='rick';
       $password='rick';
       $database='mymapping';
       $table='wdata';
       $rows=[];
       $gpxfile="";
                       
    if($_GET['gpxfile']) {
        $gpxfile=$_GET['mygpxfile'];
    }


    $cxn = mysqli_connect($hostname,$username,$password,$database)
        or die ("line 28 readgpx.php - Couldn't connect to server");                          

    $gpx =simplexml_load_file($gpxfile); //function reads xml files
    //$gpx =simplexml_load_file('waypoints.gpx'); //function reads xml files

    foreach($gpx->wpt as $wpt) {

    $nstr=$wpt->name;
    $nstr=str_replace("'","\'",$nstr); // escape ' from name

    //echo $nstr."\n";                       // print name

    $dstr=$wpt->desc;                   
    $dstr=str_replace("'","\'",$dstr);  // escape ' from desc

    $estr=$wpt->ele; // deal with no elevation data

    if($estr=="") { 
     $estr=", ''";
    }
    else {
    $estr=", ".$estr;
    }

    $sym=$wpt->sym; // deal with no symbol data

    if($sym=="") { 
     $sym=", ''";
    }
    else {
    $sym=", '".$sym."'";

    }
    //  ================  build query to input data  =====================

    $query="INSERT INTO $table (`id`, `name`, `desc`, `lat`, `lon`, `ele`,`sym`)  VALUES( NULL, ";
    $query.="'".$nstr."', '".$dstr."', ".$wpt['lat'].", ".$wpt['lon'].$estr.$sym.");";

    $result = mysqli_query($cxn, $query) or exit( mysqli_error( $cxn ));

    $query=""; // use query over again for next record

    } // foreach


    $query="SELECT * FROM ".$table." ORDER BY `name` "; // collect data just input into database 

    //echo $query;

    $res = mysqli_query($cxn, $query) or exit( mysqli_error( $cxn ));

    While($row=@mysqli_fetch_assoc($res)) {
    $rows[]=$row;
    }

    //echo "count rows ".count($rows)."\n";
    //print_r($rows);
    echo json_encode($rows); // return json to error-waypointsToDB.html
    ?>