Jump to content

Interesting situation regarding url parameters and ajax


man5
Go to solution Solved by man5,

Recommended Posts

Say my goal is to have posts with user comments with each individual post.  And these posts are posted in relavent catagories. This is all done. Works beautifully.  

 

Now say my 2nd goal is to use ajax for everytime a user posts a comment in a post, it'll load the comment without refreshing the page.  This is where I am having an issue.

 

So say this is my setup.

 

index.php

<a href="records.php?title=<?php  echo $record_id; ?>">

records.php

<head>
script type="text/javascript">
		$(document).ready(function(){

		$(".comment_button").click(function() {

		var element = $(this);
		   
			var test = $("#content").val();
			
			var dataString = 'content='+ test;
			
			
			
			if(test=='') {
			
				alert("Please Enter Some Text");
			
			}
			
			else {

				$.ajax({
				type: "POST",
				url: "ajax.php",
				data: dataString,
				cache: false,
					success: function(data){
					  
						$('#display').html(data);

						document.getElementById('content').value='';
					}
				
				});
				
				
			}
					

		return false;
		});



		});
		</script>
</head>
<body>

     <form  method="post" name="form" action="">
	     <textarea name="content" id="content" cols="45" rows="5"></textarea>
	     <input type="submit"  value="Update"  id="v" name="submit" class="comment_button"/>
      </form>

	<div id="display" align="left"> <div>

</body>

ajax.php

// need to get id of current post here.

Of course this is not the complete code but you get the idea.  The queries that insert and the get the records work.  The only issue I have is that the 'get' query won't get the current post id. It makes sense since it's in ajax.php and it's processing through the ajax function.  If that query was on records.php, yes it will work.

 

So my question is, is there a way around it?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.