I am using Ajax file upload using javascript / jQuery .
While downloading the file, I keep getting this error message: SyntaxError: invalid label
This is my JS script:
jQuery('.uploadImage').live('click',function() { ajaxFileUpload(); }); (...) function ajaxFileUpload(){ jQuery.ajaxFileUpload({ url:'../wp-content/plugins/wp-filebrowser/uploader.php', secureuri:false, fileElementId:'uploadFile', dataType: 'json', success: function (data, status){ if(typeof(data.error) != 'undefined'){ if(data.error != ''){ alert(data.error); }else{ alert(data.msg); } } }, error: function (data, status, e){ alert(data + ' - ' + status + ' - ' + e); } } ) return false; }
My PHP script works (checked before using json / jquery), but there should be something wrong with my json output from my PHP file. I tried two approaches.
I use json_encode to format the output. This is part of my PHP code:
(...) // Error message is at this stage empty. move_uploaded_file($_FILES["file"]["tmp_name"], $uploadfile); $respons = $_FILES["file"]["name"]._e(' successfully uploaded'); $data = array( "error"=> $error, "msg"=> $respons ); echo json_encode($data);
UPDATE
Turns out I used Worpdress _e() to support multilingualism. The problem is that _e() echoes the content and therefore drowns out the JSON response. When I switched to __() , it worked.
Thank you for helping mebearbore to these guys.
source share