Doğru Cevap
-
Örnek olarak bir kod veriyorum kolay gelsin..
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script> </head> <body> <script type="text/javascript"> // Document's loaded, register the click trigger $(document).ready(function() { $("#SubmitLink").click(function() { submitForm(); return false; } ); }); // Function to do the AJAX function submitForm() { $.ajax({type:"GET", url:"submit.php", data:$("#CommentsForm").serialize(), cache:false, timeout:10000, success: function() { // Request has been successfully submitted alert("Succeeded"); }, error: function() { // An error occurred, do something about it alert("Failed"); }, complete: function() { // We're all done so do any cleaning up. alert("Regardless of the outcome we're going to add the comment for demonstration purposes:"); addCommentLocally(); } }); } // Function to add the comment to the page function addCommentLocally() { $("#comments").append('<div class="comment">Field 1: '+$("#field1").val()+'<br />Field 2: '+$("#field2").val()+'<br />Field 3: '+$("#field3").val()+'</div><hr />'); $("#CommentsForm input").val(""); } </script> <h1>jQuery Example</h1> <h2>AJAX Comments</h2> <h3>Current Comments</h3> <div id="comments"> <div class="comment">Field 1: ABC<br />Field 2: DEF<br />Field 3: GHI</div><hr /> <div class="comment">Field 1: JKL<br />Field 2: MNO<br />Field 3: PQR</div><hr /> </div> <h3>Add a Comment</h3> <form id="CommentsForm" name="CommentsForm"> <p> Field 1: <input name="field1" id="field1" type="text" /><br /> Field 2: <input name="field2" id="field2" type="text" /><br /> Field 3: <input name="field3" id="field3" type="text" /> </p> </form> <p><a href="#" id="SubmitLink">Submit!</a></p> </body> </html>