Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Feb 2004
    Location
    london
    Posts
    77
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Prototype's Ajax.Request object

    Can anyone see anything wrong with this script or have any tips on using Prototype for ajax requests?

    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>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <script type="text/javascript" src="prototype.js"></script>
    <title>Prototype Form</title>
    
    <script type="text/javascript">
    
    //****************************************
    
    var BtnSubmit = $("submit");
    
    
    function ajaxcall () {
    $("ajaxform").serialize();
    
    new Ajax.Request('createxml.php',
      {
        method:'get',
        onSuccess: 
    		//Get xml node value, used below in parseMyData
    		function getNodeValue(obj,tag)
    		{
    			return obj.getElementsByTagName(tag)[0].firstChild.nodeValue;
    		}
    		
    		//Parse returned XML 
    		function parseMyData(){
    			
    			var items = responseXML.getElementsByTagName('item');
    			
    			//alert(images.length);
    			
    			if (!responseXML.documentElement && responseStream) {
    				responseXML.load(responseStream);
    			}
    			for (var i=0;i< items.length;i++)
    			{
    				var x = document.createElement('div');
    				x.className = 'holder';
    				var y = document.createElement('h3');
    				y.appendChild(document.createTextNode(getNodeValue(items[i],'title')));
    				x.appendChild(y);
    				var z = document.createElement('p');
    				z.className = 'desc';
    				z.appendChild(document.createTextNode('Description: ' + getNodeValue(items[i],'desc')));
    				x.appendChild(z);
    				document.getElementById('container').appendChild(x);
    			}
    		}
    
        onFailure: function(){ alert('Something went wrong...') }
      });
    }	
    
    </script>
    
    </head>
    
    <body>
    
    <form action="javascript: ajaxcall();" method="get" name="ajaxform" id="ajaxform">
    <fieldset><legend>Prototype test</legend>
    <label for="title">Title:</label><input type="text" name="title" size="20">
    <label for="description">Description</label><input type="text" name="description" size="20">
    <input type="submit" id="submit" value="submit" />
    </fieldset>
    </form>
    
    <div id="container">some XML?</div>
    
    </body>
    </html>
    Nothing seems to display, although I have had the Ajax.Updater working. I'm sending the request to a php document which creates an xml file from a database. I've used this script before and it has worked. If I can't find anything wrong with my js i'll have a look at the php.
    99 times out of 10!

  • #2
    Senior Coder
    Join Date
    Nov 2006
    Posts
    1,000
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It looks like you have 2 functions instead of just one in your object parameter. Also it looks like you are missing a comma before onFailure as well.

    david_kw

  • #3
    t0m
    t0m is offline
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I've tried everything I can think of to get my code working, and it doesn't work..I am using Prototype JS to do a chatroom, and I am using .PHP file's to get the users online, and the chat messages for today..Why doesn't <?php echo 'text'; ?> work with the ajax.request() of Prototype??

  • #4
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts
    You need to start your own thread that thoroughly explains your situation. Your current post doesn't say much. Try posting snippets.
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.


  •  

    Posting Permissions

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