Return a value from a function using getJSON
Hi,
I have a json file (detailing file extensions and their mime types)
I want to pass a function a file extension e.g. docx, return its associated mime type and to stop further searching through the json file
This is what I have so far but I'm getting undefined for mType in my function
- var fileExt = "docx";
- var mimeType = getMimeType(fileExt);
-
- function getMimeType(fileExt) {
- var mType;
-
- $.getJSON('json/mimeTypes.json', function(data) {
- $.each(data,function(key, value) {
- if(key == fileExt) {
- mType = value;
- }
- });
- });
-
- return mType;
- }
-
Thanks in advance