helloworld001 Posted March 17, 2015 Share Posted March 17, 2015 So I have a simple script that adds and returns mysql data without refreshing the page. Everything works as it should. The only issue that I've noticed is that if I login as a user and insert a record(text) the FIRST time, it won't return that record in the row below. Not until I refresh the page. Now if I delete that record and insert a new record, it will then automatically return the record without the page refresh, as it should. Can you tell me why this is happening? Here is my js code. <script> $(document).ready(function(){ var recordId = $("#record-id").val(); function showRecord(){ $.ajax({ type: "POST", url: "bid-actions.php", data: "recordId="+recordId+"&action=showRecord", success:function(data){ $(".show-records").html(data); } }); } showRecord(); $(document).on('click','#record-submit',function() { var message = $("#message").val(); var recordId = $("#record-id").val(); $.ajax({ type: "POST", url: "bid-actions.php", data: "message="+message+"&recordId="+recordId+"&action=insertRecord", success:function(data){ showRecord(); $("#message").val(''); } }); }); }); </script> Html code. <div id="record-submit-form"> <input type="hidden" id="record-id" value="<?php echo $record_id; ?>"> <textarea id="message"></textarea> <input type="button" id="record-submit" value="Submit"> </div> <div class="show-records"> </div> Link to comment https://forums.phpfreaks.com/topic/295324-this-is-interested-havent-noticed-until-now-ajax-wont-show-row-the-first-time/ Share on other sites More sharing options...
Psycho Posted March 17, 2015 Share Posted March 17, 2015 Can't really tell with what you've provided. But, I notice that the showRecord() function works by checking the value of the field "record-id". If you create a new record, then the ID of that record would need to be populated into that field in order to run the showRecord() function on it. I'm guessing that has something to do with the problem. Link to comment https://forums.phpfreaks.com/topic/295324-this-is-interested-havent-noticed-until-now-ajax-wont-show-row-the-first-time/#findComment-1508389 Share on other sites More sharing options...
helloworld001 Posted April 5, 2015 Author Share Posted April 5, 2015 Can't really tell with what you've provided. But, I notice that the showRecord() function works by checking the value of the field "record-id". If you create a new record, then the ID of that record would need to be populated into that field in order to run the showRecord() function on it. I'm guessing that has something to do with the problem. Well the forum is back online. The problem is fixed now. My code is correct. It's just that I was hiding the output using php if statement. Link to comment https://forums.phpfreaks.com/topic/295324-this-is-interested-havent-noticed-until-now-ajax-wont-show-row-the-first-time/#findComment-1508411 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.