Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ajax tutorial for post and get [closed]

Tags:

jquery

ajax

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!

like image 401
Reham Fahmy Avatar asked Feb 24 '12 19:02

Reham Fahmy


People also ask

How GET and POST method are used in AJAX?

GET is basically used for just getting (retrieving) some data from the server. Note: The GET method may return cached data. POST can also be used to get some data from the server. However, the POST method NEVER caches data, and is often used to send data along with the request.

Can AJAX use POST?

post() makes Ajax requests using the HTTP POST method. The basic syntax of these methods can be given with: $. get(URL, data, success); —Or— $.

How does AJAX POST work?

data : A plain object or string that is sent to the server with the request. success : A callback function that is executed if the request succeeds.it takes as an argument the returned data. It is also passed the text status of the response.


1 Answers

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 ); }); 
like image 121
apis17 Avatar answered Oct 16 '22 14:10

apis17