Uncaught typeError on ajax async upload in load-scripts.php
-
Hi,
I’m developing a WordPress site locally using Xampp on Windows 7, using the latest version of Polylang (2.3.7) and WordPress (4.9.6). I’ve built my own theme based on underscores.
For a custom post type I’ve made custom meta boxes, including an ajax image upload leveraging the built in async-upload.php of WordPress:
PHP:
$data = array( 'upload_url' => admin_url('async-upload.php'), 'ajax_url' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('media-form') ); wp_localize_script( $this->name . '-meta', 'flyer_ajax_config', $data );
HTML:
<fieldset class="pelske-event-flyer"> <legend>Upload flyer</legend> <label for="event-flyer">Upload .jpg</label> <input type="file" id="event-flyer-file" name="async-upload" size="25" /> <input type="hidden" name="image_id"> <input type="hidden" name="action" value="image_submission"> </fieldset>
jQuery:
$('#event-flyer-file').on('change', function(e){ e.preventDefault(); var $imgPreview = $('#event-flyer-preview'); var $imgFile = $('#event-flyer-file'); var $imgId = $('.pelske-event-flyer [name="image_id"]'); var formData = new FormData(); formData.append('action', 'upload-attachment'); formData.append('async-upload', $imgFile[0].files[0]); formData.append('name', $imgFile[0].files[0].name); formData.append('_wpnonce', flyer_ajax_config.nonce); $.ajax({ url: flyer_ajax_config.upload_url, data: formData, processData: false, contentType: false, dataType: 'json', type: 'POST', success: function(resp) { console.log(resp); }, error: function(resp) { console.log(resp); } }); });
This all works fine, I get a succes response and the image is indeed uploaded to my uploads folder. However it throws the following error:
load-scripts.php?c=1&load[]=hoverIntent,common,admin-bar,heartbeat,autosave,suggest,wp-ajax-response,jquery-color,wp-lists,jquery-ui-core,jquery-ui-widget,j&load[]=query-ui-mouse,jquery-ui-sortable,postbox,jquery-ui-position,jquery-ui-menu,wp-a11y,jquery-ui-autocomplete,tags-suggest,tags-box&load[]=,underscore,word-count,post,svg-painter,wp-auth-check&ver=4.9.6:8
Uncaught TypeError: a.split is not a function
at Object.unserialize (load-scripts.php?c=1&load[]=hoverIntent,common,admin-bar,heartbeat,autosave,suggest,wp-ajax-response,jquery-color,wp-lists,jquery-ui-core,jquery-ui-widget,j&load[]=query-ui-mouse,jquery-ui-sortable,postbox,jquery-ui-position,jquery-ui-menu,wp-a11y,jquery-ui-autocomplete,tags-suggest,tags-box&load[]=,underscore,word-count,post,svg-painter,wp-auth-check&ver=4.9.6:8)
at HTMLDocument.<anonymous> (post.min.js?ver=2.3.7:1)
at HTMLDocument.dispatch (load-scripts.php?c=1&load[]=jquery-core,jquery-migrate,utils&ver=4.9.6:formatted:2117)
at HTMLDocument.r.handle (load-scripts.php?c=1&load[]=jquery-core,jquery-migrate,utils&ver=4.9.6:formatted:1996)
at Object.trigger (load-scripts.php?c=1&load[]=jquery-core,jquery-migrate,utils&ver=4.9.6:formatted:2085)
at Object.a.event.trigger (load-scripts.php?c=1&load[]=jquery-core,jquery-migrate,utils&ver=4.9.6:formatted:4817)
at y (load-scripts.php?c=1&load[]=jquery-core,jquery-migrate,utils&ver=4.9.6:formatted:4023)
at XMLHttpRequest.c (load-scripts.php?c=1&load[]=jquery-core,jquery-migrate,utils&ver=4.9.6:formatted:4228)When I disable Polylang the error disappears. The only other plugin I have installed is Yoast SEO. Diving into the inspector in Chrome and prettifying load-scripts.php the variable split is being applied to does appear to be a string, so I am thoroughly confused…
Can anyone help me out?
Thanks in advance.
- The topic ‘Uncaught typeError on ajax async upload in load-scripts.php’ is closed to new replies.