To Reproduce:

  • Tested on 7.8 and 7.x-dev with PECL uploadprogress PHP module, Chrome and FF with no dev modules or extensions
  • Add a form with a managed file upload element and use the 'bar' progress indicator.
  • Upload a file

This generates an AJAX error. The response is printed in the error message. The response is an obviously corrupt json string of the form:
{ progress bar info from file_ajax_progress() } [{other ajax commands}]

The prettied up json is attached.

The Likely Cause?

I'm very new to the web designing thing but as far as I can tell, file_ajax_progress() is supposed to return an ajax command array and it doesn't. It returns nothing. Instead, it echos out the progress bar message and percentage directly. ajax_deliver() then appends the other commands and creates a bad json string with 2 arrays butted together.

Am I crazy? I've tried making file_ajax_progress() return it's $progress array (in various ways) instead of echoing it. This removes the error but the progress bar doesn't appear (although the divs are inserted for it).

Next Action

Can anyone confirm this or point me in the right direction?

Thanks muchly

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

marcingy’s picture

Status: Active » Postponed (maintainer needs more info)

Your json shows the module colourbox which is not part of core. Please disable all none core modules and see if the problem still exists.

noland’s picture

Ok. Installed a fresh minimal 7.x-dev site. Added a module containing only code found below:

function file_test_form_alter(&$form, &$form_state, $form_id){
   if($form_id == 'basic_page_node_form') {
    $file_upload['#title'] = t('File Upload');
    $file_upload['#type'] = 'managed_file';
    $file_upload['#description'] = t('Upload a managed file');
    $file_upload['#default_value'] = 0;
    $file_upload['#progress_indicator'] = 'bar';
    $file_upload['#upload_location'] = 'public://';

    $form['file_upload'] = $file_upload;
  }
}

Created a new content type on page, "basic_page", and try to add/edit this content. The following error is generated on each upload for Chrome, FF, IE 8 (with no extensions, no firebug):

(white space added for readability)

An AJAX HTTP error occurred.
HTTP Result Code: 200 
Debugging information follows.
Path: /file/progress/695667780
Status Text: OK 
ResponseText: {
    "message": "Starting upload...",
    "percentage": -1
}
[
    {
        "command": "settings",
        "settings": {
            "basePath": "\/",
            "pathPrefix": "",
            "ajaxPageState": {
                "theme": "bartik",
                "theme_token": "GDWL53RUlhqZTRtPncpqwA1cdr2iJXVEcPDjyYwQJnQ",
                "css": []
            }
        },
        "merge": true
    }
]

This error apparently only affect display of the progress bar. The file is uploaded and is intact and the managed file table is updated properly. You can also "remove" the file with the managed file widget with no errors. If #progress_indicator is set to throbber, there is no error. Again, I'm using PECL uploadprogress, not APC.

This site is available at www.locat.ca and anon users can create this content and see the error.

What should I do next?

Thanks for your help

marcingy’s picture

Version: 7.x-dev » 8.x-dev
Status: Postponed (maintainer needs more info) » Active
quicksketch’s picture

I've confirmed this problem on Drupal 7.8 while using the APC upload progress indicator. There's definitely something up with our progress bar.

quicksketch’s picture

Oh, actually 7.8 is *totally* busted due to #935208-141: PECL uploadprogress bar doesn't appear.. I'll upgrade to 7.10 and try again.

quicksketch’s picture

Status: Active » Closed (duplicate)

This issue has been fixed in Drupal 7.10 (and 8.x) by the issue mentioned in #5. Note that you have to both upgrade and manually clear the cache if you use drush for the update.

j0rd’s picture

Version: 7.15 » 8.x-dev
Status: Needs review » Closed (duplicate)

I'm getting this error (comment #2) in Drupal 7.15.

I have both Upload Progress (1.0.3.1) installed and APC (3.1.3p1) installed.

If I disable APC, I still get the error.

If I disable Upload Progress, the error goes away.

Still seems to be some kind of problem.

Exact same error as listed above, as two AJAX requests seem to be getting sent and are not valid json. I assume this is because Upload Progress is injecting it's json into the request, and so is Drupal.

I'm also using the upload in a jquery-ui modal (Media Module 2.x & File Entity).

j0rd’s picture

So as mentioned, I'm getting the same problems as comment #2, where Drupal is injecting addition JSON after the file_ajax_progress() function is called.

I assumed, this is because the function doesn't exit. I could be wrong, but in the past on D6, after you print your JSON to STDOUT, you usually exit right after. This isn't happening in file_ajax_progress() and additional Drupal ajax is getting appended to the request.

I've tried adding ajax_footer() at the end instead of exit; and I continue to get the same invalid json response.

Here's a patch which seems to resolve this issue for me. Please take a look and see if you believe this is correct, or if it would cause other errors.

j0rd’s picture

Version: 8.x-dev » 7.15
Status: Closed (duplicate) » Needs review

re-opening this issue.

silinor’s picture

Version: 8.x-dev » 7.15
Status: Closed (duplicate) » Needs review

#8 patch works for me

quicksketch’s picture

So as mentioned, I'm getting the same problems as comment #2, where Drupal is injecting addition JSON after the file_ajax_progress() function is called.

Drupal core certainly doesn't inject additional JSON, it's probably caused by a particular module that isn't behaving correctly. Drupal shouldn't need to be forcefully exit()'d, and adding an explicit exit() will cause hook_exit() to be skipped. You should try to find which module is adding the additional JSON and correcting the problem with that module.

quicksketch’s picture

Issue summary: View changes

corrected typo

webservant316’s picture

Issue summary: View changes

I am seeing this error with Drupal 7.56 and PHP71. Problem goes away with PHP70. Any tips on how to find the problem module adding extra JSON?

Version: 7.15 » 7.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.