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
    Regular Coder
    Join Date
    Aug 2006
    Posts
    181
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Ajax script does nothing

    Below you can see the code i'm using.
    I'm using it to send an id number to vote.php. Here this id should be saved in a mysql database. When i go to vote.php?id=3 directly in my browser it saves the id (3) in my mysql database so the vote.php page is totally correct and working.
    But for some reasing, when i use the link, it doesn't save the id. I do however get the alert messages that i have voted so there's nothing really wrong with the javascirptcode. Why isn't it saving the id when i click on the link?
    Code:
    <?php include("header.php");?>
    
    <!--AJAX REFRESH (hoho, (c) AdJ )-->
    <script language="javascript" type="text/javascript">
    <!-- 
    //Browser Support Code
    function ajaxFunction(id,lied){
    	var ajaxRequest;  
    	
    	try{
    		// Opera 8.0+, Firefox, Safari
    		ajaxRequest = new XMLHttpRequest();
    	} catch (e){
    		// Internet Explorer Browsers
    		try{
    			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
    		} catch (e) {
    			try{
    				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
    			} catch (e){
    				// Something went wrong
    				alert("Er is een probleem met (de instellingen van) uw browser, u kan niet stemmen!");
    				return false;
    			}
    		}
    	}
    	// Create a function that will receive data sent from the server
    	ajaxRequest.onreadystatechange = function(){
    	//	if(ajaxRequest.readyState == 4){
    	//		document.myForm.time.value = ajaxRequest.responseText;
    	//	}
    	}
    	//var id = document.getElementById('id').value;
    this.lied= lied;
    this.id= id;	
    
    	var queryString = "?id=" + id;
    	
    
    	ajaxRequest.open("GET", "http://www.webmasterhelp.biz/pilotlight/vote.php" + queryString, true);
    	ajaxRequest.send(null); 
    	alert('Merci! Je stemde voor ' + lied + '!');
    }
    
    //-->
    </script>
    <!--einde ajaxbedoening en een half uur denkwerk-->
    <div style="width:710px; height:554px; overflow:auto; 
    background-image:url(images/index_r4_c2.gif);"><img src="http://www.webmasterhelp.biz/pilotlight/Titles/Home%20Title.gif">
    <?php
    $act=$_GET['act'];
    
    
    //DB Connectie
    $host = "localhost";
    $user = "x";
    $pass = "x";
    $db   = "x";
    mysql_connect($host,$user,$pass) or die(mysql_error());
    mysql_select_db($db);
    
    $query = mysql_query("Select lied,artiest,id From proposals WHERE approved='1' ORDER BY ID DESC");
    
    ?>
    <p align="left"><u>De ingestuurde voorstellen!</u>
    <br><br>Hieronder staan alle liedjes die zijn voorgesteld op onze site. De uitzonderlijk schrale, grappige en ondoenbare voorstellen hebben we hier wel al uit geschrapt. Dit wil natuurlijk niet zeggen dat we ze ook echt spelen. Als je toch heel graag een nummer van de lijst door ons gecoverd ziet, kan je op het liedje klikken! Zo weten wij wat jullie graag zouden horen...<br>
    <br>
    <table width="90%" border="1" bordercolor="#3D515A">
    <tr bgcolor="#047391">
    	<td width="35%"><b>Artiest</b></td>
    	<td><b>Lied</b></td>
    </tr>
    <?
    $color1="#38464C";
    $color2="#1E2C32";
    $i=1;
    while($obj = mysql_fetch_object($query)){
    if($i=='1'){
     $c="$color2"; 
     }else{
     $c="$color1"; 
    }?>
    <tr bgcolor="<?php echo"$c";?>">
    	<td width="35%"><?php echo " $obj->artiest"; ?></td>
    	<td><A style="text-decoration: none;" HREF="#" onClick="ajaxFunction(<?php echo"$obj->id";?>,'<?php echo"$obj->lied";?>')"> <?php echo " $obj->lied"; ?></a></td>
    </tr>
    <?php
    if($i=='2'){$i=0;} //I RESETTEN}
    $i++;
     }?>
    </table>
    </p>
    
    
    </div>
    <?php include("footer.php");?>

  • #2
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    Have you verified that your queryString is correct? Try to alert() it before sending the request to your page.

    You pass id in as a parameter, then you have id commented out, then you have this.id=id.

    Following that line of thought, make sure this call has what you expect in it:

    Code:
    onClick="ajaxFunction(<?php echo"$obj->id";?>,'<?php echo"$obj->lied";?>')"> <?php echo " $obj->lied"; ?>
    That should probably be in your while loop.

  • #3
    Regular Coder
    Join Date
    Aug 2006
    Posts
    181
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i'll check the query with an alert, just a moment

  • #4
    Regular Coder
    Join Date
    Aug 2006
    Posts
    181
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The query is correct, if i alert the var querystring, the return box returns to me for example: ?id=54 so the squerystring is correct, then what is the problem?

  • #5
    Regular Coder
    Join Date
    Aug 2006
    Posts
    181
    Thanks
    0
    Thanked 0 Times in 0 Posts
    wtf! i changed nothing and now it's working! That's akward! Anyway, thanks a lot for trying to help!

    SOLVED!

    Thank you! Bye!


  •  

    Posting Permissions

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