I tried to make a search-bar for my current project.
Here is the current HTML:
<input type="text" id="searchbar"/>
The CSS is for now not important...
I made it possible to find files/folders from server:
If you hit enter, JavaScript sends a $.post()
Here is my Javascript:
$.post( "files/openFolder.php",{folder : $searchtext}, function() {
})
.success(function(data) {
if(data != "") {
if(data.indexOf("folder:") > -1){ //contains folders..!
foundedFolders = data;
myfolders = foundedFolders.split(/[folder:&]/);
myfolders = cleanArray(myfolders);
generateFolderBoxes(myfolders);
folderBoxSettings();
}else if(data.indexOf("file:") > -1){ // contains files..!
foundedFiles = data;
myfiles = foundedFiles.split(/[file:&]/);
myfiles = cleanArray(myfiles); //cleans the Array from empty Strings.
generateFileBoxes(myfiles);
fileBoxSettings();
}
}
})
.fail(function() {
alert("Sorry doesn't worked, try later again.");
});
My problem is here:
myfolders = foundedFolders.split(/[folder:&]/);
and
myfiles = foundedFiles.split(/[file:&]/);
PHP-Output:
"folder:****&file:*****&file:*****&"
I read this stackoverflow, to get the foldernames, or file: Get Substring between two characters using javascript
The Reg-Expression outputs:
["such", " - Kop", ".txt", "such", ".txt", "t", "st - Kop", ".txt", "t", "st.txt"]
But normaly it should be:
["suche - Kopie.txt","suche.txt","test - Kopie.txt","test.txt"]
These "filenames" are needed to display them..
Thanks for helping :D