0

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>
1
Contributor
1
Reply
2
Views
6 Years
Discussion Span
Last Post by hknight
0

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();
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.