SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Replace Text in AJAX Response (SACK Library)

    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:

    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>

  2. #2
    SitePoint Enthusiast
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I figured it out. Here is the working code:
    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();


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •