IT-info > AJAX

AJAX

jQuery AJAX GET (C#.NET)

test.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test</title>
<script type="text/javascript" src="jquery-2.1.4.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("#posttxt").click(function(){
    var textToSave = $('textarea#note').val();
    var authorName = $('input#authorname').val();

    $.ajax({
      url: 'test.aspx',
      type: 'GET',
      dataType: 'html'
,       async: true,
      data: {'text': textToSave, 'author': authorName},
      success: function(data){$("#textbox").text(data);}
    });
  });
});
</script>
</head>
<body>
<div>
<p>
<label for="notearea">Note:</label><br>
<textarea id="note" name="notearea" cols=50 rows=5></textarea>
</p>

<p>
<label for="name">Written by:</label><br>
<input type="text" id="authorname" name="name">
</p>

<p><button id="posttxt">Submit</button></p>
</div>

<div id="textbox"></div>
</body>
</html>

test.aspx

<%@ Page Language="C#" %>

<%
string noteText = Request.QueryString["text"];
string aName = Request.QueryString["author"];

Response.Write("Hallo " + aName + ". You wrote: " + noteText);
%>