943,175 Members | Top Members by Rank

Ad:
Sep 2nd, 2010
0

Replace Content from AJAX Result (SACK)

Expand Post »
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:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <title>Example</title>
  5. <script type="text/javascript" src="http://www.twilightuniverse.com/downloads/sack/tw-sack.js"></script>
  6. </head>
  7. <body>
  8.  
  9. <div id="r"></div>
  10.  
  11. <input type="button" value="Click Here to Test" onclick="runAjax()" />
  12.  
  13. <script type="text/javascript">
  14. /*<![CDATA[*/
  15.  
  16. function runAjax() {
  17.  
  18. var aj = new sack();
  19. aj.setVar('item', 'value');
  20. aj.requestFile = 'submit.html';
  21. aj.method = 'POST';
  22. aj.element = 'r';
  23. aj.runAJAX();
  24. alert('I want ABC to be replaced with XYZ.');
  25.  
  26. }
  27.  
  28. /*]]>*/
  29. </script>
  30.  
  31. </body>
  32. </html>
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
hknight is offline Offline
11 posts
since Dec 2008
Sep 3rd, 2010
0
Re: Replace Content from AJAX Result (SACK)
I figured it out. Here is the working code:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. var aj = new sack();
  2. aj.requestFile = f.getAttribute('action');
  3. aj.method = f.getAttribute('method').toUpperCase();
  4. aj.onCompletion = function () {
  5. if (document.getElementById(win)) document.getElementById(win).innerHTML = aj.response.replace(/ABC/g, 'XYZ');
  6. };
  7. aj.runAJAX();
Reputation Points: 10
Solved Threads: 0
Newbie Poster
hknight is offline Offline
11 posts
since Dec 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Show / Hide table rows via checkboxes
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Radio Button onClick Javascript calling only once





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC