In this example, I want "ABC" to be replaced with "XYZ":
http://pastehtml.com/view/1avqmak.html

I am posting data using AJAX and I want to use JavaScript to replace the response before the response is returned. If you test the link above you will see the issue.

Here is my code:

<!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>
<title>Example</title>
<script type="text/javascript" src="http://www.twilightuniverse.com/downloads/sack/tw-sack.js"></script>
</head>
<body>

<div id="r"></div>

<input type="button" value="Click Here to Test" onclick="runAjax()" />

<script type="text/javascript">
/*<![CDATA[*/

function runAjax() {

	var aj = new sack();
	aj.setVar('item', 'value');
	aj.requestFile = 'submit.html';
	aj.method = 'POST';
	aj.element = 'r';
	aj.runAJAX();
	alert('I want ABC to be replaced with XYZ.');

}

/*]]>*/
</script>

</body>
</html>

I figured it out. Here is the working code:

var aj = new sack();
            aj.requestFile = f.getAttribute('action');
            aj.method = f.getAttribute('method').toUpperCase();
            aj.onCompletion = function () {
                if (document.getElementById(win)) document.getElementById(win).innerHTML = aj.response.replace(/ABC/g, 'XYZ');
            };
            aj.runAJAX();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.