The 500 error in Ajax JavaScript is causing issues with the

Here is the javascript code for a simple multifile upload functionality.

While this javascript works perfectly on my development server, I encounter a 500 error on the AJAX Post when I try to use it on my production server. Could this issue be related to the need for further edits in php.ini? Or are there other underlying problems causing this error?

var app = app || {};

(function(o){
"use strict";

var ajax, getFormData, setProgress;

ajax = function(data){
  var xmlhttp = new XMLHttpRequest(), uploaded;

  xmlhttp.addEventListener('readystatechange', function(){
     if(this.readyState ===4){

        if(this.status===200){
           //console.log('here');
           uploaded = JSON.parse(this.response);
           if(typeof o.options.finished==='function'){
              o.options.finished(uploaded);
           }
        }else{
           if(typeof o.options.error ==='function'){
              o.options.error();
           }
        }            
     }
  });

  xmlhttp.upload.addEventListener('progress', function(event){
     var percent;
     if (event.lengthComputable ===true){
        percent = Math.round((event.loaded / event.total)*100);
        //console.log(percent);
        setProgress(percent);
     }
  });

  xmlhttp.open('post', o.options.processor);
  xmlhttp.send(data);
};
getFormData = function(source){
  var data = new FormData(), i;

  for( i=0;i<source.length;i=i+1){
     data.append('file[]',source[i]);
  }
  data.append('ajax',true);
  return data;
 };

 setProgress = function(value){
  if(o.options.progressBar !== undefined){
     o.options.progressBar.style.width=value? value + '%': 0; 
  }
  if(o.options.progressText !== undefined){
     o.options.progressText.innerText=value? value + '%': ''; 
  }
 };
 o.uploader = function(options){
  o.options = options;

  if(o.options.files!== undefined){
     ajax(getFormData(o.options.files.files));
  }
 };
}(app));

Answer №1

giorgio assisted me in finding the correct path I had been using $uploaded = []; in my php code, but I believe this is outdated PHP syntax and the right way is to use $uploaded = array();. I have around 5 arrays in my code and it seems that XAMPP is flexible enough to execute whatever code I provide.

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

Having difficulty including my JavaScript file located in /app/assets/javascripts when using Rails 4 and "//= require_tree ." in application.js

I'm currently attempting to implement a d3.js graph into my Rails 4 application by following a tutorial found on this website. The example application provided on GitHub works perfectly as expected. The issue I am facing is that when I try to recreat ...

Having trouble sending a file with a form using JQuery AJAX?

Looking for assistance with an AJAX function utilizing JQuery: var formData = $('#FonykerEditForm').serialize(); $.ajax ({ type: 'POST', url: '<?php echo $html->url('/fonykers/edit',true); ?>', ...

What is the proper way to manage an AJAX request with Spring MVC? What could be the reason this code is not functioning as expected in my project?

I am still learning about Spring MVC and AJAX and encountering a specific issue. On a particular page, my application triggers a JavaScript function that makes an AJAX GET request: function loadRegionDetail(selectedRegion) { var regionCode = selectedR ...

The IISNode website displays directory contents instead of launching the server.js file

Having trouble configuring IISNode to automatically serve the main server.js application file for my node application. Currently, when I navigate to http://localhost:80/ where my app is hosted, it just displays the folder contents instead of running the se ...

In nextjs, the page scroll feature stops functioning properly following a redirection

Currently, I am running on version 13.5.4 of Next.js In a server-side component, I am using the nextjs redirect function to navigate to another page. However, after the redirection, I noticed that the next page is missing the scroll bar and seems to be st ...

Application route is failing to direct to the HTML page

On my MEAN stack website, I am trying to make the browser navigate to a file named 'findCable.html' but it keeps directing to 'singleCable.html'. I have double-checked the angular routing file and backend routes, but can't see ...

Sharing data between Jasmine JavaScript tests: a complete guide

Currently, I am conducting tests involving reading and writing data (to a server, to a mongo db). While I understand that I should be using mocks for this purpose, I have found a workaround to achieve my goal of writing a document, validating its accuracy ...

The implementation of pushing inside a foreach loop is not correctly adding elements to

I have encountered an issue with running a foreach loop and adding values to an array in my code. The first foreach loop works as expected, adding values properly to the array. However, the second foreach loop seems to be malfunctioning as none of its valu ...

What is the best method for updating the .value property within an AngularJS controller?

I managed to successfully pass a value from one AngularJS module to another using the .value method. Here is an example of it working: var app = angular.module('app', []); app.value('movieTitle', 'The Matrix'); var app1 =ang ...

Data retrieval seems to be encountering issues in Firefox and IE9, whereas Chrome and Safari are functioning without any problems

I am using the following method function callCommentservice() { try { // Comment Service Url var getCommentServiceUrl = self.commentsServiceUrl + self.getRating + "tenantId=" + self.tenantId + "&ratedObjectTypeId=" + sel ...

A prompt box in Internet Explorer using the InternetExplorer.Application in PowerShell

I'm having trouble adding a value to the pop-up window. Here is the code: <!DOCTYPE html> <html> <body> <h2>PS Prompt test</h2> <button onclick="Function()" id="test">send value</button> <p id="demo"&g ...

React component utilizes Material UI to detect scrolling within a table

Currently, my table's body size is set to fixed dimensions in accordance with Material UI guidelines. I am looking to implement a functionality that allows me to dynamically load more rows as the user scrolls through the table. Can you recommend the ...

Firebase version 9 - Retrieve the content of a referenced document

I'm having trouble locating the documentation I need. Within my Firebase Firestore project, there is a collection called users. Within users, there are three collections: companies, policies, and stores. In the policies collection, I have fields for ...

Tips for passing the element ID as an argument in the jQuery upvote plugin function

var updateVote = function(data) { $.ajax({ url: '/vote/', type: 'post', data: { id: data.id, up: data.upvoted, down: data.downvoted, ...

What is the best way to turn off ajax functionality when detecting IE8?

Encountering a significant problem where every time the save/cancel button is clicked, IE8 freezes (while Firefox and Chrome work without issue). When JavaScript is disabled in the browser, it works correctly. There is a suspicion that an ajax call linke ...

Tips for initializing dynamic fields created using ng-repeat?

When I have the following HTML code in my view, dynamically generated using ng-repeat: <div ng-repeat="item in selectedProcedures track by $index"> <span style="display:none;">{{item.id}}</span> <div class="row" ng-repeat="it ...

What is the best way to link my React application with my Express API?

I've been immersed in my react app project for a while now, and I've recently delved into developing a server (using node and express) as well as planning to incorporate a database for it (MongoDB). My client-side react app has been smoothly run ...

Retrieve data from a text file stored locally, store it in an array, and populate a <select> dropdown with the

Greetings! I am working on an application in htaEdit where I require to read a text file line by line and insert each line into a select dropdown. Here is the code for the select dropdown: <select onchange="disableCategory();" style="width:220px;m ...

What's the best way to load a series of chat messages in typescript?

I am currently working on developing a web chat application using ionic, and I have encountered an issue with loading and displaying messages. Below is the code snippet that I am using to load messages from the database: <ion-item *ngFor="let mesag ...

Validation in ASP.Net to ensure the correct number of days between the arrival and departure dates

One of my project requirements involves checking the validation of the number of days entered between two date selectors (From & To Dates). The constraint is that the difference should not exceed 100 days. I'm considering using ASP.NET validators for ...