Take AJAX to your Email Inbox: Developing the Client-side Application Layer - Collecting connection data: defining the "getFormValues()" function
(Page 3 of 6 )
As I described above, all the "getFormValues()" function does is get the values entered by the user when trying to establish a connection to the mail server. In plain English this means obtaining the name or IP address of the mail server, along with the corresponding username/password combination, to be transmitted in the form var1=value1&var2=value2...&varN=valueN.
As you know, this is really a simple task to do, so the signature for the function is the following:
function getFormValues(fobj){
var str='';
for(var i=0;i< fobj.elements.length;i++){
str+=fobj.elements[i].name+'='+ escape(fobj.elements
[i].value)+'&';
}
str=str.substr(0,(str.length-1));
return str;
}
Here, the above function accepts the web form to be processed as the one input argument and loops over its fields, in order to get the values in question. After the iteration process on the form has been performed, the function returns the form values, as an appropriately formatted string, to the calling code. Simple and sweet.
At this stage, I've demonstrated how the POP3 client can connect to the mail server, after submitting the correct data combination. However, assuming that the connection was successfully established...how are the email messages displayed on the web page? To answer this question, I'll define another useful function, which I called "fetchMessages()," tasked with showing messages retrieved from the mail server.
Let's jump to the next section and see how this function works.
Next: Displaying email messages: defining the "fetchMessages()" function >>
More XML Articles
More By Alejandro Gervasio