1

I maintain a web app that uses CKeditor in conjunction with simogeo Filemanager. At some point (I am, unfortunately, not sure when) the file upload functionality stopped working. It's not a server code issue (at least not directly) because the XHR request is never sent to the server. Beyond that, though, the issue is difficult to diagnose because I don't get much in the way of information from the browser when the request fails.


To simplify debugging I am using a modified version of the AJAX file upload sample from here: https://github.com/New-Bamboo/example-ajax-upload

<?php
if ( isset( $_FILES['our-file'] ) ) {
    echo 'You uploaded ' . $_FILES['our-file']['name'];
    exit();
}
?>

<!--
https://github.com/New-Bamboo/example-ajax-upload
-->

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8" />
  <title>Ajax upload form</title>
</head>
<body>

<form action="index.php" method="post" enctype="multipart/form-data" id="form-id">

<p><input id="file-id" type="file" name="our-file" />
<input type="submit" value="Submit" /></p>

<script>
var form = document.getElementById('form-id');
form.onsubmit = function() {
  var formData = new FormData(form);
  var action = form.getAttribute('action');
  sendXHRequest(formData, action);
  return false;
}

function sendXHRequest(formData, uri) {
  try {
    var xhr = new XMLHttpRequest();
    xhr.addEventListener('readystatechange', evtXHR , false);
    xhr.addEventListener('timeout', evtXHR , false);
    xhr.addEventListener('error', evtXHR , false);
    xhr.open('POST', uri, true);
    xhr.timeout = 3000;
    xhr.send(formData);
  } catch (err) {
    result.innerHTML = err;
  }
}

function evtXHR (evt) {
  var status = null;

  try {
    status = evt.target.status;
  }
  catch(e) {
    return;
  }

  var result = document.getElementById('result');
  var msg = result.innerHTML + '<hr>';
  if (status == '200' && evt.target.responseText) {
    msg += '<p>Results from the server:</p><pre>' + evt.target.responseText + '</pre>';
  }
  msg += '<p>XMLHTTPRequest Event ' + evt.type + '<br>';
  msg += 'XMLHTTPRequest Status ' + evt.target.status + '<br>';
  msg += 'XMLHTTPRequest Readystate ' + evt.target.readyState + '</p>';
  result.innerHTML = msg;
}
</script>

<pre id="result"></pre>

</form>
</body>
</html>

Upon form submission (xhr.send()) the request dies without any kind of helpful error. Firefox kills the request and indicates it has been aborted (from the Firebug net panel). IE similarly kills the request with the following error in the console:

XMLHttpRequest: Network Error 0x2efe, Could not complete the operation due to error 00002efe.

Googling has offered little in the way of direction. The few possible explanations were too many requests, overlapping requests cancelling each other out, or request timeouts. None of those appear relevant. Mozilla has a note about stopped requests that seems potentially helpful, but isn't directly related to my issue.

The issue only crops up when submitting over AJAX using a POST request that includes a file. Submitting a regular, non-AJAX request works fine. Submitting an AJAX request without a file goes through just fine. Submitting a GET request works, but that severely limits the data size. Submitting the request to an HTML document instead of a PHP script seems to work around the issue.

On a server with a very similar configuration I an unable to duplicate the issue. I have, however, reproduced the issue on the same server using two different domains. And the issue can be duplicated on two different client computers using a variety of browsers.

So ... what now? Looking for either an answer or at least a suggestion for how to debug the issue.

You can find the simple upload script here: http://flora.p2061.org/fileup

Community
  • 1
  • 1
BrianS
  • 13,284
  • 15
  • 62
  • 125
  • Can you post the AJAX code? – TheCarver Dec 12 '13 at 03:45
  • All the code is wrapped up into the Filemanager package. I just set a few configuration options, which are the same between the two systems. – BrianS Dec 12 '13 at 03:53
  • I know you’ve probably searched for answers. Have you looked at this one? http://stackoverflow.com/questions/14527387/script7002-xmlhttprequest-network-error-0x2ef3-could-not-complete-the-operati – Nate Dec 12 '13 at 03:54
  • I did (once I tracked down where the AJAX configuration object was being set). It caused Firefox to throw a JS error: `TypeError: b is null`. – BrianS Dec 12 '13 at 04:08
  • Also of note, this only appears to happen if I'm doing a file upload. Normal form data is POSTed via AJAX just fine. – BrianS Dec 20 '13 at 17:43
  • Ok, so I simplified the problem by utilizing the following code: https://github.com/New-Bamboo/example-ajax-upload. The request is still being killed before being sent to the server, while a nearly identical server shows no issues. – BrianS Dec 20 '13 at 20:09
  • Made significant changes to cover what I've done and what I know. – BrianS Dec 20 '13 at 20:54
  • What happens if specifying a *full* URI to the XHR call? – user2864740 Jan 06 '14 at 20:03
  • @user2864740 one of these days someone will propose a solution so simple, so obvious, that I would have to turn in my keyboard. This was not it. But thanks, because I hadn't yet tried that one. – BrianS Jan 06 '14 at 21:19
  • what is sitting on the other end of your test script? Is it supposed to return the contents of the file on success? or does `index.php` simply spit back the test page regardless of request type? – Emissary Jan 06 '14 at 21:28
  • @Emissary when you submit the form it returns the name of the file you submitted. You can see a functional version here: http://eclecticgeek.com/bugs/fileup/ – BrianS Jan 06 '14 at 21:48
  • Okay, I was sitting playing around with it but can't for the life of me see anything wrong - sorry if I'm making you reiterate stuff but the fact that the same script works on a different domain screams server issue to me. When you say the request is never sent to the server how are you determining that? - it's not necessarily going to be obvious from a browser debugger. – Emissary Jan 06 '14 at 22:27
  • I'll tell you what I think is happening, your working version is running on a standard Apache/PHP setup - happy days. Your broken version is running on some kind of FastCGI/suPHP option etc. *(I'm not really clued up on the nuances between them)* but in some setups when a PHP script fails it just kills the process - ***i.e.*** no response at all (inc. headers). Have you tried enabling PHP errors for debugging? If I were a betting man - and I am - my money is on either a simple permissions or chmod issue. – Emissary Jan 06 '14 at 22:42
  • I think you have the broken vs. working platforms backwards. The broken one is on Apache w/ modphp. No doubt it's a server issue, but I can't figure out what. However, it's not the general software configuration because I have a private server that is almost identically configured that does not exhibit the same behavior. Definitely something with that server ... I just can't figure out what. – BrianS Jan 06 '14 at 22:48
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/44655/discussion-between-brians-and-emissary) – BrianS Jan 06 '14 at 22:48

1 Answers1

0

Post resolved as a server-side issue in chat - shamefully restarting apache cleared the issue :/ but for anyone interested the transcript is available here. There may (or not) be useful dialogue for anyone with a similar issue.

Community
  • 1
  • 1
Emissary
  • 9,954
  • 8
  • 54
  • 65
  • 1
    A restart? In linux? [It's not fair ... It's not my fault!](http://starwars.com/watch/encyclo_its_not_my_fault.html) Oh ... just take my keyboard, I no longer deserve it. – BrianS Jan 07 '14 at 00:09