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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jan 2009
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Ajax request not working?

    I've made a couple of these work, but it is so hard to bug test them!

    My script:
    Code:
    <script type="text/javascript" src="prototype.js"></script>
    <script>
    function sendRequest() {
    
    		new Ajax.Request("ajaxshowsearch.php", 
    					{ 
    					method: 'post', 
    					postBody: 'Showtype='+$F(Showtype)+'&dog_id='+$F(dog_id),
    					onComplete: showResponse 
    					});
    				
    				}
    
    			function showResponse(req){
    				$('foo').innerHTML= req.responseText;
    			}
    </script>
    
    
    <form id=test action=shows.php? onsubmit="return false;">
    Dog:
    HERE;
    $query=mysql_query("select name,dog_id,breed from dogs where player_id='$player_id' and age < 108 and train_complete=1 and weight >= 90 and weight <= 110 and trust >= 50");
    if(mysql_num_rows($query) != "0"){
    	print "<select name=dog_id>";
    while($row=mysql_fetch_array($query)){
    	print "<option value=$row[dog_id]>$row[name] (#$row[dog_id]), $row[breed]</option>";
    }
    print "</select><br>";
    }
    else{
    print "No dogs eligible for showing.<br>";
    }
    
    print "<select name='Showtype[]' multiple>
    <option>Flyball</option>
    <option>Obedience</option>
    <option>Agility</option>
    <option>HTM</option>
    </select><br>";
    if(mysql_num_rows($query) != "0"){
    	print "<input type=submit name=submit value='Search Shows' onClick=sendRequest()>";
    }
    print "</form>";
    ?>
    
    
    <div id="foo"></div>
    Absolutely nothing happens when the form button is pressed. Help? TIA.

    PS- most of my script is cut out, this is just the vitals. In "ajaxshowsearch.php" the word "test" resides, so I know the error is not there.

    -Alyssa

  • #2
    Regular Coder ohgod's Avatar
    Join Date
    Jun 2008
    Location
    Ohio
    Posts
    579
    Thanks
    6
    Thanked 69 Times in 69 Posts
    as far as hard to debug, grab firebug for firefox... you can watch the whole transaction. or i guess the lack thereof...

  • #3
    New to the CF scene
    Join Date
    Jan 2009
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Alright, I got Firebug. How do I use it?

  • #4
    New to the CF scene
    Join Date
    Jan 2009
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I figured out how to use Firebug, it is saying "Showtype is not defined" though it looks like it is. Any suggestions?

  • #5
    Regular Coder ohgod's Avatar
    Join Date
    Jun 2008
    Location
    Ohio
    Posts
    579
    Thanks
    6
    Thanked 69 Times in 69 Posts
    for the record... this should probably be in the framework section since you're working with prototype.


    change $F(Showtype) to $F('Showtype[]')

    when using the $F utility method the element needs to be in single quotes (unless the element name is a variable passed as an arg or something). Also, you need the [] as it is part of the name.


    And just another thought... if you know you're going to take all values from the form, then
    $('yourform').serialize()
    would\could replace
    'Showtype='+$F(Showtype)+'&dog_id='+$F(dog_id)

    but for that matter, since you're using this to update another section you might just use Ajax.Updater. it's very easy to use, and would take:
    Code:
    function sendRequest() {
    
    		new Ajax.Request("ajaxshowsearch.php", 
    					{ 
    					method: 'post', 
    					postBody: 'Showtype='+$F(Showtype)+'&dog_id='+$F(dog_id),
    					onComplete: showResponse 
    					});
    				
    				}
    
    			function showResponse(req){
    				$('foo').innerHTML= req.responseText;
    			}
    and turn it into:
    Code:
    new Ajax.Updater( 'foo', 'ajaxshowsearch.php', 
    			    { method: 'post', parameters: $('test').serialize()
    				} );


  •  

    Tags for this Thread

    Posting Permissions

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