Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery works only when the user enters the site for the first time
    primarykey
    data
    text
    <p>I am doing a sticky note web site where users can post msg etc onto post it notes. I am using jQuery UI with PHP. I was hoping to use AJAX to make it responsive but am having some issues with the page updating via ajax. </p> <p>The main issue is my jQuery appears to only work when the user enters the site for the first time, when they add some info through a form (and to database) my jQuery UI behaviour (i.e. drag and drop, getting attributes and position elements with CSS) stops working until a page refresh. It is like my ajax is passing new looped PHP content and jQuery is no longer recognising the .class I have applied!</p> <p>Hopefully this or my code makes sense, I am still new to ajax and coding in general.</p> <p>Main page - pert.php</p> <pre><code> &lt;html&gt; &lt;header&gt; &lt;link rel="stylesheet" href="style.css" type="text/css"/&gt; &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"&gt;&lt;/script&gt; &lt;link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/themes/base/jquery-ui.css"/&gt; &lt;script type="text/javascript" src="js/fancybox/jquery.fancybox-1.3.4.pack.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="js/fancybox/jquery.easing-1.3.pack.js"&gt;&lt;/script&gt; </code></pre> <p></p> <pre><code>&lt;script type="text/javascript"&gt; jQuery(document).ready(function() { $("#addtask").submit(function() { //$("#form").serialize(); $.post('update.php', $("#addtask").serialize(),function(data){ $("#result").html(data); }); return false; //stop browser refresh }); //looping through Post it Notes to apply to all within class $(".task").each(function(index){ //store x, y from looped php var x = $(this).attr("x"); var y = $(this).attr("y"); //assign looped php to css $(this).css("left",x); $(this).css("top",y); //attach draggable behaviour $(this).draggable({ cursor: 'move', stack: '.post', opacity: '0.5', containment: '#container' }); //store variables x, y and id for database via mouse move and ajax $(this).mouseup(function(){ var coord=$(this).position(); var h = $(this).height(); var w = $(this).width(); var coordLeft = coord.left; var coordTop = coord.top; var noteid = $(this).attr("taskid"); })//loop done })//jquery end &lt;/script&gt; &lt;/header&gt; &lt;body&gt; &lt;h4&gt;Draggable Stickies&lt;/h4&gt; &lt;!--&lt;p&gt; Click here to &lt;a class = "addimage" href="addimage.html"&gt;Add image&lt;/a&gt; &lt;/p&gt;--&gt; &lt;form id="addtask"&gt; Task Desc:&lt;input type="text" name="taskdesc"/&gt; &lt;input type="submit" value="Enter"/&gt; &lt;/form&gt; &lt;div id="result"&gt; &lt;? include "connectdb.php"; //looping through stored desc $querySticky=mysql_query("SELECT * FROM tasks"); while($r=mysql_fetch_array($querySticky)){?&gt; &lt;div class="task" x="&lt;? echo $r["x"]; ?&gt;" y="&lt;? echo $r["y"]; ?&gt;" id="&lt;? echo $r["taskid"]; ?&gt;"&gt; x=&lt;? echo $r["x"]; ?&gt; y=&lt;? echo $r["y"]; ?&gt;&lt;p&gt;&lt;? echo $r["taskdesc"];?&gt;&lt;/p&gt; &lt;/div&gt; &lt;?}?&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>accessing database - update.php</p> <pre><code> &lt;? include("connectdb.php"); if(ISSET($_POST['taskdesc'])){ $taskdesc = $_POST['taskdesc']; $queryinsert1="INSERT INTO tasks(taskdesc)VALUES('$taskdesc')"; $result=mysql_query($queryinsert1); } //for updating coordinates in database not in use y if(ISSET($_POST['taskid'])){ $x = $_POST['x']; $y = $_POST['y']; $id = $_POST['taskid']; $addxyquery="UPDATE tasks SET x = '$x', y ='$y' WHERE taskid='$id'"; $result=mysql_query($addxyquery); } //looping through stored desc for updated results $querySticky=mysql_query("SELECT * FROM tasks"); while($r=mysql_fetch_array($querySticky)){?&gt; &lt;div class="task" x="&lt;? echo $r["x"]; ?&gt;" y="&lt;? echo $r["y"]; ?&gt;" id="&lt;? echo $r["taskid"]; ?&gt;"&gt; x=&lt;? echo $r["x"]; ?&gt; y=&lt;? echo $r["y"]; ?&gt;&lt;p&gt;&lt;? echo $r["taskdesc"];?&gt;&lt;/p&gt; &lt;/div&gt; &lt;?}?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload