Hi, I'm having trouble in making an ajax call with an html button. Can anyone answer my questions? Thanks in advance!
url: comment.php?id=1 Question 1: how do I get the php variable $_REQUEST['id'] in jquery? Question 2: when I clicked the button, the url goes back to comment.php. How can I make it to go back to comment.php?id=1? Here is the code: <html> <head> <title>testing</title> <link rel="stylesheet" type="text/css" href="../../theme/ stylesheet.css"> <script type="text/javascript" src="../../includes/jquery-1.3.2.js"></ script> <script type="text/javascript"> function submitToggle() { if ($('#submit').css('display') == 'none') { $('#submit').slideDown(); } else { $('#submit').slideUp(); } } function submitCommentToggle() { if ($('#comment-TA').css('display') == 'none') { $('#comment-TA').slideDown(); } else { $('#comment-TA').slideUp(); } } //add click handler for button $("#comment_add").click(function() { //alert($.post('id')); //define ajax config object var ajaxOpts = { type: "post", url: "addComment.php", data: "&author=" + $("#comment-TA").find("input").val() + "&comment=" + $("#comment-TA").find("textarea").val() + "&id=1" //need to replace with $REQUEST['id'] //success: function(data) { //alert("succeed!"); //create a container for the new comment //var div = $("<div>").addClass("print-comment").appendTo ("#comments-section"); }; //$.ajax(ajaxOpts); }); //}); </script> </head> <div class="Comments"> <div class="comment_button"><a href="javascript:submitCommentToggle ()" class="comment_button">Add a Comment</a></div> <body> <div id="comment-TA"> <div class="row"> <label>Name:</label><input type="text"/> </div> <form class="comment-textbox"> <textarea></textarea><br /> <button id="comment_add"> Comment </button> </form> </div> <div id="comments-section"> <div class="print-comment"> <label>name:</label> <div class="printed-comment-msg">message</div> </div> </div> </div> </body> Thanks, Chuck.