Jack Ben Jack Ben - 2 years ago 93
jQuery Question

Ajax tutorial for post and get

I need a simple ajax tutorial or case study for a simple input form, where I want to post a username through an input form, which sends it to the database and replies with the results.

Any recommendation for such tutorial is welcome, because I've only got one using Mootool but I'm searching for one using jQuery!

Answer Source

You can try this:

  url: "test.html",
  cache: false,
  success: function(html){

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

You can find more information at jQuery website.


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 );
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download