lunged Posted May 9, 2012 Share Posted May 9, 2012 I found a topic that helped, but isn't quite doing it for me yet… http://www.phpfreaks.com/forums/index.php/topic,257587.msg1211752.html#msg1211752 I am attempting to make a simple restaurant list were you can check off places you have been. I am using Jquery mobile, with PHP, AJAX and a MySQL database. This is my first use of Ajax outside of basic tutorials and I'm not sure where I am going wrong. Any help would be appreciated! The main code: <div data-role="fieldcontain"> <fieldset data-role="controlgroup" > <?php $query = "SELECT * FROM restaurants "; $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $id = stripslashes($row['id']); $restaurantname = stripslashes($row['restaurantname']); $visited = stripslashes($row['visited']); ?> <input type="checkbox" name="res_<?php echo $restaurantname ?>" id="res_<?php echo $restaurantname; ?>" value="<?php echo $restaurantname; ?>" class="custom" onchange="ajaxFunction(<?php echo $id; ?>, this.checked);" <?php if ($visited == '1') {echo "checked";} ?> /> <label for="res_<?php echo $restaurantname ?>"><?php echo $restaurantname ?></label> <?php } ?> </fieldset> </div> The JS: <script type="text/javascript"> function ajaxFunction(uid, uvisited) { var ajaxRequest; // The variable that makes Ajax possible! 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("Your browser broke!"); return false; } } } uvisited = (uvisited==true ? "1" : "0"); var url = "updatevisited.php?id="+uid+"&visited="+uvisited; ajaxRequest.open("GET", url, true); ajaxRequest.send(null); } </script> The PHP: <?php include("dbinfo.inc.php"); mysql_connect($hostname,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $uvisited=$_GET['uvisited']; $uid=$_GET['uid']; $queryUpdateVisited="UPDATE restaurants SET visited='$uvisited', timestamp='NOW()' WHERE id='$uid' "; mysql_query($queryUpdateVisited) or die(mysql_error()); ?> Quote Link to comment Share on other sites More sharing options...
Jessica Posted May 9, 2012 Share Posted May 9, 2012 You haven't said what errors you get, what unexpected output, or lack of output, etc. We can't guess where you're going wrong without more info. I'm curious why you have all sorts of browser checks if you're using jquery. It's supposed to do that stuff for you. Quote Link to comment Share on other sites More sharing options...
The Letter E Posted May 14, 2012 Share Posted May 14, 2012 Yea dude. I don't see one lick of jQuery in your posted code... That's a standard JS ajax request function and probably not going to work in all browsers/devices. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.