Jump to content

This is interested. Haven't noticed until now. Ajax won't show row the first time.


helloworld001

Recommended Posts

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>

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.

  • 3 weeks later...

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.