man5 Posted March 19, 2014 Share Posted March 19, 2014 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? Quote Link to comment https://forums.phpfreaks.com/topic/287102-interesting-situation-regarding-url-parameters-and-ajax/ Share on other sites More sharing options...
jazzman1 Posted March 20, 2014 Share Posted March 20, 2014 you should focus into the data comming from the html textarea field, the content of this field will be send to the server and receive some response using ajax. Quote Link to comment https://forums.phpfreaks.com/topic/287102-interesting-situation-regarding-url-parameters-and-ajax/#findComment-1473259 Share on other sites More sharing options...
Solution man5 Posted March 20, 2014 Author Solution Share Posted March 20, 2014 I think my question was confusing. But I have a solution. I had to to set $_SESSION variable to get an idea of a different page. It works. Quote Link to comment https://forums.phpfreaks.com/topic/287102-interesting-situation-regarding-url-parameters-and-ajax/#findComment-1473345 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.