REQUEST A DEMO

AJAX to the rescue!

Situation

 

One of our Dovetail Agent customers ran into an issue trying to log an email that contained extended ASCII characters. One of the email pages supports creating emails with multiple file attachments, and uses a VB component called aspSmartUpload to process the email form. The issue in this case is that aspSmartUpload (version 3.3) does not have support for CodePage recognition, so extended ASCII characters don’t get passed through in the correct character set. The email would be sent correctly, but the email history was being saved to the database with the incorrect characters.

Solution

 

After vainly searching for a newer version of aspSmartUpload, it was decided to save the text fields before the form submission, and to retrieve and use the text data for the email history, without having to drastically change the email pages or replace the aspSmartUpload component.

 

The solution is to make a quick jQuery ajax post and then submit the form as the callback function. The ajax function happens very quickly, and everything stays synchronized correctly by waiting until the callback to submit the form to aspSmartUpload.

 

There are just three areas that were changed, so it is pretty simple to show some of the code here.

 

On the client side, the form submit was replaced with a call to this function:

function saveSessionDataAndSubmitForm() {
    var messageData = {
       subject: $("#subject").val(),
       message: $("#message").val()
    }

    $.ajax({
       type: "POST",
       url: "saveSessionData.asp",
       dataType: "json",
       data: messageData,
       success: function(results) {
          if(results.success == true) {
             $("#frmLogEmail").submit();
          } else {
             alert("An error occurred while saving Session Contents: " + results.errorMessage);
          }
       },
       error: function(xhr) {
          alert("An error occurred while saving Session Contents");
       }
    });
}

 

 

The ajax page itself just gets the posted data and saves it to Session.Contents variables:

 

<%@ Language=JavaScript %>
<% Response.Buffer = true %>

<!--#include file="../include/inc_page_init.asp"-->
<!--#include file="../include/json.asp"-->

<%
var result = {};
result.success = true;
result.errorMessage = "";

try {

   var strSubject = Request.Form("subject").Item;
   var strMessage = Request.Form("message").Item;

    Session.Contents("eeoSubject") = strSubject;
    Session.Contents("eeoMessage") = strMessage;

} catch(e) {
   result.success = false;
   result.errorMessage = e.description;
}

Response.Clear();
Response.Write(JSON.stringify(result));
%>

 

 

After that, then the email form itself is submitted, and in that page the Session Content variables are checked and used if available:

  var eeoSubject = Session.Contents("eeoSubject");
  var eeoMessage = Session.Contents("eeoMessage");

  if(eeoMessage > "") {
      strSubject = eeoSubject;
      strMessage = eeoMessage;
  }

  Session.Contents("eeoSubject") = "";
  Session.Contents("eeoMessage") = "";

Conclusion

 

Once again, the ease of use of jQuery quickly led to a simple solution. True, this is a work-around for an outdated VB component, but being able to solve the customer’s problem without having to totally refactor the code is a definite benefit.