Ajax tutorial for post and get [closed]

Solution 1:

You can try this:

$.ajax({
  url: "test.html",
  cache: false,
  success: function(html){
    $("#results").append(html);
  }
});

This code will append the content of test.html file to #results element

You can find more information at jQuery website.

Update:

Use this code to send POST data and output result.

var menuId = $("ul.nav").first().attr("id");
var request = $.ajax({
  url: "script.php",
  type: "POST",
  data: {id : menuId},
  dataType: "html"
});

request.done(function(msg) {
  $("#log").html( msg );
});

request.fail(function(jqXHR, textStatus) {
  alert( "Request failed: " + textStatus );
});

Solution 2:

Assuming you have some html like:

<input type="text" name="username" id="username">
<div id="resultarea"></div>

You would use a <script> like:

var myusername = $("#username").val();
$.ajax({
  type: "GET",
  url: "serverscript.xxx",
  data: myusername,
  cache: false,
  success: function(data){
     $("#resultarea").text(data);
  }
});