Ajax POST FormData not defined
-
For some reason when i use this code in my wordpress site (localhost) it throws an ‘no index defined’ error, yet when i test it in a non-wordpress environment, the ‘cvfiles’ is defined and all functions work and run as expected.
Any thoughts as to why? code below from localhost:-// detect file upload type $('#cvfiles').change(function(event) { var uploadData = $(this).val(); var extType = uploadData.split('.').pop(); if (extType == "txt") { console.log('txt file found'); readBlobTxt(); } else if (extType == "docx") { data = new FormData(); data.append( 'cvfiles', $( '#cvfiles' )[0].files[0] ); $.ajax({ url: "https://localhost/wp/wp-content/themes/twentyfourteen/inc/ajax_php_file_rename.php", // Url to which the request is send type: "POST", // Type of request to be send, called as method data: data, contentType: false, // The content type used when sending data to the server. cache: false, // To unable request pages to be cached processData:false, // To send DOMDocument or non processed data file it is set to false success: function(data) // A function to be called if request succeeds { console.log(FormData); console.log('success'); // run scan function file var fileLocal = 'https://localhost/wp/wp-content/themes/twentyfourteen/inc/uploads/' + uploadData; $.get('readfile.php?fileUrl=' + fileLocal, function(data) { console.log('Load was performed.'); document.getElementById('cv-content').textContent = data; scanPortfolioDocX(); }); } }); } else if (extType == "doc") { // stuff here } else if (extType == "pdf") { // stuff here } else { console.log('other file found'); } });
ajax_php_file_rename code below:-
<?php $UploadDirectory = 'https://localhost/wp/wp-content/themes/twentyfourteen/inc/uploads/'; // upload directory $File_Name = strtolower($_FILES['cvfiles']['name']); $FileName_No_Ext = var_dump(basename($File_Name, '.docx')); $File_Ext = substr($File_Name, strrpos($File_Name, '.')); //get file extention $Random_Number = rand(0, 9999999999); //Random number to be added to name. $NewFileName = $FileName_No_Ext.$Random_Number.$File_Ext; //new file name if(move_uploaded_file($_FILES['cvfiles']['tmp_name'], $UploadDirectory.$File_Name )) { // do other stuff die('Success! File Uploaded.'); }else{ die('error uploading File!'); } ?>
sorry cant add a link as site is still on localhost.
Thanks
- The topic ‘Ajax POST FormData not defined’ is closed to new replies.