Forum Member - UzuNarU posted this ajax solution to pull content from an outside page and placing it in a <div> tag in this forum (His code post)... and it's working great for us... with one big exception...
We sometimes have javascript code coming back using this ajax process - and it won't display.
Is there a trick do getting javascript ajax to display a javascript content.
e.g. sample code that could be return using this ajax solution. Apparently we are 'nesting' javascript code.
<script type='text/javascript'><!--// <![CDATA[
var ox_swf = new FlashObject('http://xxxxxxxx/haas_tn468x60.swf', 'Advertisement', '468', '60', '10');
ox_swf.addVariable('clickTARGET', '_blank');
ox_swf.addVariable('clickTAG', 'http%3A%2F%2Fxxxxxxx%3D60698__zoneid%3D0__cb%3D655fbc6d60');
ox_swf.addParam('allowScriptAccess','always');
ox_swf.write('ox_69efb414458c63b218d5b1aeb7b05b8b');
// ]]> --></script>
Thanks to anyone who would respond!!
For the people who still look at this thread. This is a AJAX JavaScript which allows you to call an external page, query string or whatever you desire and send it to a specified DIV eg:
<a href="javascript:void()" onclick="javascript:sendRequest('sourcepage?id=34', 'targetdiv')">Link Text</a>
<div id="targetdiv">This is the target</div>
This makes it so that users of your site can see the script being passed to get the results that are displayed.
function createRequestObject()
{
var returnObj = false;
if(window.XMLHttpRequest) {
returnObj = new XMLHttpRequest();
} else if(window.ActiveXObject) {
try {
returnObj = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
returnObj = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {}
}
}
return returnObj;
}
var http = createRequestObject();
var target;
// This is the function to call, give it the script file you want to run and
// the div you want it to output to.
function sendRequest(scriptFile, targetElement)
{
target = targetElement;
try{
http.open('get', scriptFile, true);
}
catch (e){
document.getElementById(target).innerHTML = e;
return;
}
http.onreadystatechange = handleResponse;
http.send();
}
function handleResponse()
{
if(http.readyState == 4) {
try{
var strResponse = http.responseText;
document.getElementById(target).innerHTML = strResponse;
} catch (e){
document.getElementById(target).innerHTML = e;
}
}
}