Initiating an Ajax request to OGRE converter

Has anyone had success using the OGRE online converter to convert shape-files to a different format? I have been attempting to make this conversion by referring to . I have set up an AJAX call to send the file and receive the response, however, the response is returning with the error message "Cannot read property 'path' of undefined."

Below is a snippet of the code used for the AJAX call. The variable sFile represents the file uploaded through the control. I have tried various methods to attach the file as the 'data' parameter in the AJAX call (e.g. creating a FormData object, creating an object, etc.), but I keep encountering the same error.

    function shapeFileProcessing(sFile){
           
         var formdata = new FormData();
         formdata.append("upload", sFile);
                   
         var obj = {};
         obj.upload = sFile;
                     
           $.ajax({
                  url : 'http://ogre.adc4gis.com/convert',
                  data : obj,
                  type : "POST",
                  success : function(msg) {
                    console.log("Success: "+msg);
                  }
          });
    }

Additionally, when I tested the same process using Postman, it was successful in converting the file and providing it as a response [![enter image description here][1]][1]) [1]: https://i.sstatic.net/EJO8T.jpg

Answer №1

Your AJAX request is missing the actual formdata object being appended, instead another object called "obj" is present:

data : obj

To avoid getting the error

Uncaught TypeError: Illegal invocation
, you need to specify the following as well:

processData: false,
contentType: false,

The revised function should look like this:

function uploadFile(data){

  var formdata = new FormData();
  formdata.append("file", data);

  $.ajax({
    url: 'https://example.com/upload',
    data: formdata,
    type: "POST",
    processData: false,
    contentType: false,
    success: function(response) {
      console.log("Upload successful: "+response);
    }
  });
}

Demo:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Preventing Page Refresh in Laravel while Utilizing QueryBuilder

In my laravel application, I am utilizing the spatie/laravel-query-builder to filter a list of jobs based on different categories. This is how my code currently looks: Controller: public function index(Request $request) { $regions = Region::all(); ...

The enigmatic dance of Angular and its hidden passcodes

Recently, I've been diving into learning Angular 2 and I'm exploring ways to safeguard the data in my application. I'm curious about how one can prevent data from being accessed on the front end of the app. Could serving the angular app thr ...

What measures can be taken to safeguard this hyperlink?

Is there a way to conceal HTML code from the source code? For instance: jwplayer("mediaplayer").setup({ file: "http://example.com/Media.m3u8", autostart: 'true', controlbar: 'bottom', file: "http://exa ...

Looking for a way to replicate the functionality of a switch case within an object literal function

When working with a switch case, the default case handles any scenarios that are not covered by the expected cases. To simplify my code and reduce cyclomatic complexity, I ended up replacing the switch case with an object literal function. function test() ...

Creating a smooth transition effect for a welcoming message using PHP upon logging in

In the given code snippet for setting a cookie on a website, the logic is such that it checks if the cookie with user's full name already exists. If it does, it immediately displays a welcome message to the user and redirects them to the home page aft ...

What exactly does white space signify during the inspection process?

For quite some time now, I've been experiencing a strange problem with webpack. The layout in Dev seems to be slightly different than the build. While inspecting in Firefox, I noticed that the difference lies in the white space. My question is, what e ...

What could possibly be the reason for the malfunctioning light in this particular setting?

Recently, I developed a game class using Coffeescript that showcases both a static and rotating cube. If you are interested in checking out the code, you can find it here: http://jsfiddle.net/6eRzt/6/ Despite everything working smoothly, there are two iss ...

Unable to utilize the PATCH method in SailsJS version 1.0

I'm working with Sails v1.0 and using active blueprints APIs to interact with my model. I recently encountered an issue when trying to update a field in my model using an Ajax call with the PUT method. The system returned a message stating: debug: ...

Unable to modify headers after they have already been sent to the client - an error has occurred

I am encountering an issue when trying to redirect the page to another page. Everything works fine with the first post request, but starting from the second one, I keep getting this error message: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after t ...

Is it possible to assign a deconstructed array to a variable and then further deconstruct it?

Is there a way to deconstruct an array, assign it to a variable, and then pass the value to another deconstructed variable all in one line of code? Take a look at what I want to achieve below: const { prop } = [a] = chips.filter(x => x.id == 1); Typic ...

Adjusting Text Size Depending on Width

I recently used an online converter to transform a PDF into HTML. Check out the result here: http://www.example.com/pdf-to-html-converted-file The conversion did a decent job, but I'm wondering if it's feasible to have the content scale to 100% ...

PHP failed to respond to the AJAX request

Currently, I am in the process of developing a straightforward signup page that utilizes jQuery and PHP with AJAX functionality. The following script is responsible for initiating the ajax call: <script> function submitForm(){ var data1=$( ...

The Issue of a Table Without Choices

Seeking clarification on an issue concerning tables. Can anyone help with this? Issue1: I have created a Single Page Application (SPA) with a table in plunker1:http://plnkr.co/edit/LJ81NedMa88Q7EhFrLmw?p=preview (Navigate to Tab2, select a date and submit ...

What is the process for transferring the value from a list item to the search field box?

I have developed a Bootstrap/jQuery function that can display the item matching the user's search query. However, I am facing some challenges in making the selected item populate the search field or providing clear validation to the user once it is ch ...

The hyperlink functionality in NextJS is not functioning properly on Vercel during production

I recently deployed my NextJS site to Vercel. While I can navigate between pages locally, like to "/workshop", nothing happens when I click the Workshop button in production. The Workshop button is located in the Navbar.js file. <Link href="/workshop"&g ...

Utilizing React Javascript leaftlet library to implement functionality to zoom in on map using state

As a beginner in programming and leaflet, I've encountered a roadblock in my code. Check out my code snippet: import "./App.css"; import { MapContainer, TileLayer, Marker, Popup } from "react-leaflet"; import { useEffect, useState ...

How come the filter function produces different results compared to using push with a for..of loop?

After extracting an array of objects from the raw data provided in this link, I have encountered a dataset that resembles the following: [0 ... 99] 0 : city : "New York" growth_from_2000_to_2013 : "4.8%" latitude : 40.7127837 longitude : -74.0059413 popul ...

What could be causing the href to malfunction within nav tabs in Bootstrap version 4?

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstra ...

Guide for redirecting from the controller side following an Ajax call in Rails 6?

Is there a way to redirect using the controller in Rails 6 after an ajax request? I attempted to achieve this by using redirect_to "url"; return and render :js => "window.location.reload" but unfortunately it did not work for me. Your assistance is g ...

Implementing Adaptive Images in Bootstrap 5 for a Specified Design

I am currently working on a website layout that involves displaying one image per section. My goal is to have the images positioned on either side of the text when viewed on a larger screen, as shown in the example below: https://i.sstatic.net/bms6S.png ...