In this example, I want "ABC" to be replaced with "XYZ":

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" "">
<html xmlns="">
<script type="text/javascript" src=""></script>

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

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

<script type="text/javascript">

function runAjax() {

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




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');
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.