# Thread: xmlHttpRequest not working for email script

1. Registered User
Join Date
Apr 2017
Posts
4

## xmlHttpRequest not working for email script

I'm trying to pull a msg file from the server to display in a basic email reader script so Outlook isn't needed. I'm struggling every which way. The console log says there's no JavaScript on the page... even though the script type='text/javascript'. I just get a blank page with no errors!

Code:
var message;
console.log('Testing console');
function httpGetAsync(theUrl, callback){
var xmlHttp = new XMLHttpRequest();
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
callback(xmlHttp.responseText);
message = xmlHttp.responseText;
}
xmlHttp.open("GET", theUrl, true); // true for asynchronous
xmlHttp.send(null);
}

httpGetAsync('\Test.txt', function(resp) { \\tried 'Test.txt' also... really need to be able to input 'z:\whole\path\to\test.txt'
console.log(resp);
});

//This part is email reader that works with 3 other external scripts
function isSupportedFileAPI() {
return window.File && window.FileReader && window.FileList && window.Blob;
}

function formatEmail(data) {
return data.name ? data.name + " [" + data.email + "]" : data.email;
}

$(function () { if (isSupportedFileAPI()) {$('.src-file').change(function () {
var selectedFile = message; //removed Browse button... this.files[0];

if (!selectedFile) {
$('.msg-info, .incorrect-type').hide(); return; } if (selectedFile.name.indexOf('.msg') == -1) {$('.msg-info').hide();
$('.incorrect-type').show(); return; }$('.msg-example .msg-file-name').html(selectedFile.name);
$('.incorrect-type').hide(); // read file... var fileReader = new FileReader(); fileReader.onload = function (evt) { var buffer = evt.target.result; var msgReader = new MSGReader(buffer); var fileData = msgReader.getFileData(); if (!fileData.error) {$('.msg-example .msg-from').html(formatEmail({name: fileData.senderName, email: fileData.senderEmail}));

$('.msg-example .msg-to').html(jQuery.map(fileData.recipients, function (recipient, i) { return formatEmail(recipient); }).join('<br/>'));$('.msg-example .msg-subject').html(fileData.subject);
$('.msg-example .msg-body').html( fileData.body ? fileData.body.substring(0, Math.min(500, fileData.body.length)) + (fileData.body.length > 500 ? '...' : '') : '');$('.msg-example .msg-attachment').html(jQuery.map(fileData.attachments, function (attachment, i) {
return attachment.fileName + ' [' + attachment.contentLength + 'bytes]' +
(attachment.pidContentId ? '; ID = ' + attachment.pidContentId : '');
}).join('<br/>'));
$('.msg-info').show(); // Use msgReader.getAttachment to access attachment content ... // msgReader.getAttachment(0) or msgReader.getAttachment(fileData.attachments[0]) } else {$('.msg-info').hide();
$('.incorrect-type').show(); } }; fileReader.readAsArrayBuffer(selectedFile); }); } else {$('.msg-example').hide();
\$('.file-api-not-available').show();
}
});

2. You do not "GET" when posting a form, you "POST" the form and you have to use the command xmlhttp.send( null ) because you are saying send nothing and the form needs to send data for it to work and you don't need any JQuery to get or for fomatting the email, you cn do that on the server, just get the raw data to the server, validate it and then send it in an email. The form data needs to be passed as a parameter because yu won't be getting data to the server, you use something like xmlhttp.send( document.forms.yourFormName ) you can pass the form object itself. you also have to set the correct enctype attribute in HTML form element, again you need a web form to do this and if you don't have a web form element then this is another problem to resolve as well.

3. Registered User
Join Date
Apr 2017
Posts
4
Remember remember and thank you for your reply \\.\, however it's not an email form. There are pdf and msg files on the server that are correspondence or information about a project. I'm able to display the pdf's quite easily, but I'm having a problem with the msg files. I found a msg reader script, and since it runs on the client it seems to me there would need to be a call to the server, basically a clickable icon link... to GET the file via xmlHTTPrequest, then display it using the basic reader script so Outlook isn't needed. The basic email reader script was made use of a Browse button to find the msg file. I can't use that of course, because the msg file is on the server. I've tried a number of ways... in the example above, I had tried assigning it with var selectedFile = message; but it just displays blankness with no error.

4. Registered User
Join Date
Apr 2017
Posts
5
Hi, the first thing i see that maybe you use "Internet Explorer" and are not solving the XDomainRequest problem?

If it's not that, then you could use "Chrome" (for example) and check your site with it's "developer tools". There you'll find error messages and further options to test your site.

Hope that helps...

5. Registered User
Join Date
Apr 2017
Posts
5
did you include jQuery?

6. Registered User
Join Date
Apr 2017
Posts
5
Originally Posted by mirkov
Hi, the first thing i see that maybe you use "Internet Explorer" and are not solving the XDomainRequest problem?
Sorry, forget that part... i'm actually, probably pretty tired. :-) jQuery makes the AJAX-call happen...
but i would maybe find a full app that works out of the box.. instead of trying to fix something that doesn't... (just in case you didn't write it yourself)

Cheers

7. Registered User
Join Date
Apr 2017
Posts
4

## Nowhere Fast

I'm mostly testing in Firefox, sometimes Chrome... less often IE. This is as close to "out of the box" as I could find. I've tested the email reader on the client side and it works fine. It seems to be mostly a matter of getting an xmlHTTPRequest to pull a file from the Server instead of using a Browse button to find a file on the local machine... because I'm eliminating the Browse button entirely. I tried outputting xmlHTTPRequest to message; then assigned var selectedFile = message; but it gets me a blank page with no errors.

8. Registered User
Join Date
Apr 2017
Posts
4
I've got xmlHTTPRequest working... it was a network error issue, but I get a 404 page now when I try to display .msg file. The file is there, because I can change the extension to .txt and it will display jibberish... (maybe I'm there, and it just needs to be plugged into the reader script somewhere?) Besides that, I thought if I used overrideMimType it would help, but it displays [object blob].

There are currently 1 users browsing this thread. (0 members and 1 guests)

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

"

"

## X vBulletin 4.2.2 Debug Information

• Page Generation 0.48325 seconds
• Memory Usage 2,924KB
• Queries Executed 16 (?)
Template Usage (34):
• (1)bbcode_code
• (1)bbcode_quote
• (1)footer
• (1)forumjump
• (1)forumrules
• (1)gobutton
• (8)memberaction_dropdown
• (1)navbar
• (1)navbar_moderation
• (1)navbar_noticebit
• (1)navbar_tabs
• (2)option
• (8)postbit
• (8)postbit_onlinestatus
• (8)postbit_wrapper
• (1)spacer_close
• (1)spacer_open
• (1)tagbit_wrapper

Phrase Groups Available (6):
• global
• inlinemod
• postbit
• posting
• reputationlevel
Included Files (26):
• ./global.php
• ./includes/class_bootstrap.php
• ./includes/init.php
• ./includes/class_core.php
• ./includes/config.php
• ./includes/functions.php
• ./includes/class_friendly_url.php
• ./includes/class_hook.php
• ./includes/class_bootstrap_framework.php
• ./vb/vb.php
• ./vb/phrase.php
• ./includes/functions_calendar.php
• ./includes/functions_bigthree.php
• ./includes/class_postbit.php
• ./includes/class_bbcode.php
• ./includes/functions_reputation.php
• ./includes/functions_notice.php
• ./packages/vbattach/attach.php
• ./vb/types.php
• ./vb/cache.php
• ./vb/cache/db.php
• ./vb/cache/observer/db.php
• ./vb/cache/observer.php

Hooks Called (73):
• init_startup
• friendlyurl_resolve_class
• init_startup_session_setup_start
• database_pre_fetch_array
• database_post_fetch_array
• init_startup_session_setup_complete
• global_bootstrap_init_start
• global_bootstrap_init_complete
• cache_permissions
• fetch_postinfo_query
• fetch_postinfo
• fetch_foruminfo
• global_state_check
• global_bootstrap_complete
• global_start
• style_fetch
• global_setup_complete
• strip_bbcode
• friendlyurl_clean_fragment
• friendlyurl_geturl
• forumjump
• cache_templates
• cache_templates_process
• template_register_var
• template_render_output
• fetch_template_start
• fetch_template_complete
• parse_templates
• notices_check_start
• notices_noticebit
• process_templates_complete
• friendlyurl_redirect_canonical
• bbcode_fetch_tags
• bbcode_create
• postbit_factory
• postbit_display_start
• postbit_imicons
• bbcode_parse_start
• bbcode_parse_complete_precache
• bbcode_parse_complete
• postbit_display_complete
• memberaction_dropdown
• tag_fetchbit
• tag_fetchbit_complete
• forumrules
• navbits
• navbits_complete