EDIT - 0 - Still need to fix markup language to make more unique so escaping is not needed:
This will be a JSON / JQuery Alternative.
/********************
group:ajax
********************/
/*
- ajax_object() - creates a browser dependent ajax_object for the ajax method call
- good place to add mysql logging to track object usage and reshape code via machine learning
- ouptut - returns false or ajax_object
*/
function ajax_object()
{
var object;
try
{
object=new XMLHttpRequest();
}
catch(error_1)
{
alert('ajax_object : not instantiated:contact-support@archemarks.com : Error : ' + error_1)
}
return object;
}
/*
- ajax() - post style ajax
- 'path' holds the servers side function to respond to the request
- 'param' hold the serialized information to send the server
- 'ajax_func' holds the javascript function to respond to the server
- 'div' div holds the html location to send the response text
- Output: returns 1 for pass.
*/
function ajax(path,param,ajax_func,html_div)
{
var object=new ajax_object();
object.open("POST",path,true);
object.setRequestHeader("Content-type","application/x-www-form-urlencoded");
object.setRequestHeader("Content-length",param.length);
object.setRequestHeader("Connection","close");
object.onreadystatechange=function()
{
if(this.readyState===4)
{
if(this.status===200)
{
if(this.responseText!=null)
{
ajax_func(this.responseText,html_div);
}
else alert("ajax: responseText is null")
}
else alert('AJAX FAIL: Path - ' + path + ' .status = ' + this.status + ' . responseText = ' + this.responseText)
}
}
object.send(param);
return 1;
}
/*
- "enumeration" for aml_status_type
*/
var aml_status_type =
{
"pass":0,
"fail":1,
"undefined":2
}
/*
- check_aml()
*/
function check_aml(text)
{
var aml_response=patterns.aml.exec(text);
if(aml_response)
{
if(aml_response[2]=='p')
{
return aml_status_type.pass;
}
else if (aml_response[2]=='f')
{
return aml_status_type.fail;
}
}
else
{
return aml_status_type.undefined;
}
}
/*
- ajax_signin()
*/
function ajax_signin(server_response_text,html_div)
{
var aml_status=check_aml(server_response_text.slice(0,6));
if(aml_status===aml_status_type.pass)
{
reload();
}
else if(aml_status===aml_status_type.fail)
{
document.getElementById(html_div).innerHTML='';
document.getElementById(html_div).innerHTML=server_response_text;
}
else if(aml_status===aml_status_type.undefined)
{
server_response_text=server_response_text.substr(6);
alert('php error: ' + server_response_text);
}
}
/*
- ajax_singup()
*/
function ajax_signup(server_response_text,html_div)
{
aml_status=check_aml(server_response_text.slice(0,6));
if(aml_status===aml_status_type.pass)
{
document.forms['upload_form'].submit();
}
else if(aml_status===aml_status_type.fail)
{
document.getElementById(html_div).innerHTML=server_response_text;
}
else if(aml_status===aml_status_type.undefined)
{
server_response_text=server_response_text.substr(6);
alert('php error: ' + server_response_text);
}
}
/*
- ajax_bookmark()
*/
function ajax_bookmark(server_response_text,html_div)
{
aml_status=check_aml(server_response_text.slice(0,6));
if(aml_status===aml_status_type.pass)
{/*add code here when ready */}
else if (aml_status===aml_status_type.fail)
{/*add code here when ready */}
else if (aml_status===aml_status_type.undefined)
{
server_response_text=server_response_text.substr(6);
alert('php error: ' + server_response_text);
}
}
/*
- ajax_tweet() - takes in sturctured data and converts to html - remove the conversion into another method
*/
function ajax_tweet(server_response_text,html_div)
{
var first_split,second_split,tweet_count,return_string='';
var aml_status=check_aml(server_response_text.slice(0,6));
if(aml_status===aml_status_type.pass)
{
server_response_text=server_response_text.substr(6);
first_split=server_response_text.split(/\|\|/);
for(tweet_count=0;tweet_count<first_split.length;tweet_count++)
{
second_split=first_split[tweet_count].split(/\|/);
return_string=return_string+'<div class="Bb2b"><img class="a" src="pictures/' + second_split[0] + '.jpg" alt=""/><a class="a" href="javascript:void(0)\">' + second_split[1] + ' posted ' + view_date(second_split[2],second_split[3]) + '</a><br/><p class="c">' + second_split[4] + '</p></div>';
}
fill_id(html_div,return_string);
}
else if (aml_status===aml_status_type.fail)
{/*add code here when ready */}
else if (aml_status===aml_status_type.undefined)
{
server_response_text=server_response_text.substr(6);
alert('php error: ' + server_response_text);
}
}
/*
- ajax_null()
*/
function ajax_null()
{
}