0

I'm working on a project using geoserver and openlayers plus web development technologies like html, javascript,jQuery, Ajax, bootsrap .. Users of my project should import a shapefile from their device on my web site and it shoud be displayed on the map. So i triyed to work geoserver-client-php to import the zipped shapfile to geoserver and then displaying it using openlayers but even when there's no error in the console the shapefile doesn't get uploaded to geoserver .

i am using Ajax to send the request.

Here it is my JavaScript code:

$("#btnSubmit").on('click', function () {
  
    var form = new FormData(this);
    
    $.ajax({
      url: "main.php",
      type: "POST",
      data: form,
      contentType: false,
      cache: false,
      processData: false
    });
  });

Here it is my HTML code:

          <form id="importForm" enctype="multipart/form-data">
            <div class="modal-body">
              <div class="mb-3">
                <label for="formFileMultiple" class="form-label">Choose your file:</label>
                <input class="form-control" type="file" name="file" id="importInput"  multiple>
              </div> 
            </div>
            <div class="modal-footer">
              <button id="btnSubmit" type="submit" name="submit" class="btn btn-danger" value="Upload">Import</button>
            </div>
          </form>

Here it is my PHP code:

<?php

  require_once("../vendor/autoload.php");


use OneOffTech\GeoServer\GeoServer;
use OneOffTech\GeoServer\Auth\Authentication;
use OneOffTech\GeoServer\GeoFile;

if(isset($_POST['submit'])){
  $fileU = $_FILES['file'];
  $realName = explode('.', $fileU['name']);
  $filePath = realpath($fileU["tmp_name"]);

  
  
  $url = 'http://localhost:8081/geoserver/';

  $workspace = 'assia';

  $authentication = new Authentication('admin', 'geoserver');

  $geoserver = GeoServer::build($url, $workspace, $authentication);

  $workspace = $geoserver->workspace();

  $file = GeoFile::load($filePath);
  $file -> name($realName[0]);
  $feature = $geoserver->upload($file);

}
GIS_Girl
  • 1
  • 1
  • I don't see you preventing the submit button click default action, so this will probably submit your form "normally", which will cancel any ongoing AJAX requests at that point. – CBroe Aug 09 '22 at 10:03
  • Hello @CBroe i didn't get you well, could you please explain more! – GIS_Girl Aug 10 '22 at 00:05
  • https://stackoverflow.com/questions/6462143/prevent-default-on-form-submit-jquery – CBroe Aug 10 '22 at 06:14

0 Answers0