Here is the main file:
Code:
<MIVA STANDARDOUTPUTLEVEL=""><MvDO FILE = "./config.mvc">
<MIVA STANDARDOUTPUTLEVEL="text, html, compresswhitespace">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>AJAX Testing</title>
<script type="text/javascript">
// setup for all ajax calls
var ajax_url = "<MvEVAL EXPR = "{ g.site_lib_ajax }">";
// AJAX controllers
// Tries different methods because different browsers create the Object differently
function createRequest() {
try {
request = new XMLHttpRequest();
} catch ( tryMS ) {
try {
request = new ActiveXObject("Msxml2.XMLHTTP");
} catch ( otherMS ) {
try {
request = new ActiveXObject("Microsoft.XMLHTTP");
} catch ( failed ) {
request = null;
}
}
}
return request;
}
// Two functions for getting debug code on the screen
function Debug(scope) {
// Get the Object
debugRequest = createRequest();
// If it fails, alert us
if (debugRequest == null)
alert("Unable to create request");
else {
// Craft the url of where we are going to get the source of data
var url= ajax_url + '?security=' + debug_security_string + '&scope=' + scope;
// If something happens to the current state (like a drop down or a link press), call "GetDebugStatus()". Cannot included parameters
debugRequest.onreadystatechange = GetDebugStatus;
// Connect to the url we set up. Differences between "GET" and "POST", true and false, and using null are too much to explain here
debugRequest.open("GET", url, true);
debugRequest.send(null);
}
}
// This is called because something happened. Trust me and check for readyState == 4 and status == 200.
function GetDebugStatus() {
if (debugRequest.readyState == 4) {
if (debugRequest.status == 200) {
// we connected and got back informatoin, so process whatever has been sent back
// Assume was we got back is text. JSON or plain text uses .responseText, XML uses .responseXML
var stringData = debugRequest.responseText;
// Find <div id="debug"></div> on the page, and paste in what we got back
document.getElementById('debug').innerHTML = stringData;
}
}
}
</script>
<link rel="stylesheet" href="css/default.css" />
</head>
<body>
<form method="POST" action="" class="css_class" id="anyform" name="anyform">
<h2>Test Debug</h2>
<fieldset>
<legend>Debug</legend>
<p><MvEVAL EXPR = "{ Debug() }"></p>
</fieldset>
</form>
</body>
</html>
<MvEXIT>
<MvFUNCTION NAME = "Debug" STANDARDOUTPUTLEVEL = "text, html, compresswhitespace">
<MvEVAL EXPR = "{ [ g.site_lib_utils ].Get_Parameters( l.parameters ) }">
<MvASSIGN NAME = "l.parameters" MEMBER = "type" VALUE = "{ 'debug' }">
<MvASSIGN NAME = "l.string" VALUE = "{ [ g.site_lib_utils ].Encode_Session( l.parameters ) }">
<script type="text/javascript">
var debug_security_string = "<MvEVAL EXPR = "{ l.string }">";
</script>
<p><a href="javascript:Debug('s');">Debug system variables</a></p>
<p><a href="javascript:Debug('g');">Debug global variables</a></p>
<p><a href="javascript:Debug('d');">Debug database variables</a></p>
<p><a href="javascript:Debug('l');">Debug local variables</a></p>
<p><a href="javascript:Debug('');">Clear</a></p>
<p><div id="debug"></div></p>
</MvFUNCTION>
And here is the ajax module file:
Code:
<MIVA STANDARDOUTPUTLEVEL="">
<MvDO FILE = "./config.mvc">
<MvEVAL EXPR = "{ Send_Headers() }">
<MvEVAL EXPR = "{ AJAX_Debug( g.scope ) }">
<MvEXIT>
<MvFUNCTION NAME = "Send_Headers" STANDARDOUTPUTLEVEL = "">
<MvASSIGN NAME = "l.null" VALUE = "{ miva_output_header( 'Expires', 'Mon, 26 Jul 1997 05:00:00 GMT' ) }">
<MvASSIGN NAME = "l.null" VALUE = "{ miva_output_header( 'Cache-Control', 'no-cache, must-revalidate' ) }">
<MvASSIGN NAME = "l.null" VALUE = "{ miva_output_header( 'Pragma', 'no-cache' ) }">
<MvASSIGN NAME = "l.null" VALUE = "{ miva_output_header( 'Content-Type', 'application/json' ) }">
</MvFUNCTION>
<MvFUNCTION NAME = "AJAX_Debug" PARAMETERS = "scope" STANDARDOUTPUTLEVEL = "">
<MvASSIGN NAME = "l.scope" VALUE = "{ tolower( l.scope ) }">
<MvIF EXPR = "{ NOT ( l.scope IN 'sgdl' ) }">
<MvASSIGN NAME = "l.scope" VALUE = "s">
</MvIF>
<MvASSIGN NAME = "l.list" VALUE = "{ miva_getvarlist( l.scope ) }">
<MvASSIGN NAME = "l.count" VALUE = "1">
<MvASSIGN NAME = "l.debug" VALUE = "">
<MvASSIGN NAME = "l.return" VALUE = "">
<MvWHILE EXPR = "{ gettoken( l.list, ',', l.count ) }">
<MvASSIGN NAME = "l.token" VALUE = "{ gettoken( l.list, ',', l.count ) }">
<MvASSIGN NAME = "l.return" VALUE = "{ l.return $ '{' }">
<MvASSIGN NAME = "l.return" VALUE = "{ l.return $ '"token":"' $ l.token $ '"' }">
<MvASSIGN NAME = "l.return" VALUE = "{ l.return $ ', ' }">
<MvASSIGN NAME = "l.return" VALUE = "{ l.return $ '"value":"' $ encodeattribute( miva_variable_value( l.scope $ '.' $ l.token ) ) $ '"' }">
<MvASSIGN NAME = "l.return" VALUE = "{ l.return $ '}' }">
<MvASSIGN NAME = "l.count" VALUE = "{ l.count + 1 }">
<MvIF EXPR = "{ gettoken( l.list, ',', l.count ) }">
<MvASSIGN NAME = "l.return" VALUE = "{ l.return $ ', ' }">
</MvIF>
</MvWHILE>
<MvIF EXPR = "{ len( l.return ) }">
<MvASSIGN NAME = "l.return" VALUE = "{ '[' $ l.return $ ']' }">
</MvIF>
<MvFUNCTIONRETURN VALUE = "{ l.return }">
</MvFUNCTION>