Php jquery ajax post method s, php jquery ajax post request example

Last update: May 29, 2018• Date posted: September 25, 2013COMMENTS• 13 Comments / in jQuery / Posted by MIKE DALISAY
RELATED TUTORIAL: PHPhường, MySQL and AJAX CRUD Tutorial – Step by Step Guide!

Today I’m gonmãng cầu give you some code examples on how you can post a size and JSON data using jQuery AJAX.

A PHPhường tệp tin will receive sầu the posted data and print the response.

Bạn đang xem: Php jquery ajax post method s, php jquery ajax post request example

I think this is one of the most useful code when you’re coding with jQuery, especially if you’re building a web app with modules that deals with so many forms or post request in one page.

Why use jQuery for AJAX requests?

I think it is to lớn make things easier, have shorter more readable code. You can see some code examples of doing an AJAX request without jQuery here và here.

As you can see on those links, some tasks include creating a catch for different browser XMLHttpRequest, opening the url, checking if the request is in ready state and setting the request header.

jQuery solves this by having a short, more readable syntax.

Xem thêm: nhan vien van phong tai da nang

Let’s code!

Alright, now we’ll get straight lớn the code examples. We’re gonna have three example below, continue khổng lồ read!

1. jQuery post size data using .ajax() method

This is a great way khổng lồ show someone that you are now an AJAX programmer. Because of this .ajax() piece of code in your HTML page, you may now face the world with confidence và with a beautiful smile in your face.

Just kidding. But seriously, this piece of code is useful.

jQuery post size data using .ajax() method by obatambeienwasirherbal.com

jQuery post khung data using .ajax() method

Fill out and submit the form below lớn get response.
<đầu vào type="text" name="lastname" placeholder="Lastname" />
<đầu vào type="text" name="email" placeholder="Email" />

2. jQuery post form data using .post() method

.post() method has a more descriptive syntax, it is a shorth& of .ajax() method above sầu. See how it was commonly used with the code below:

jQuery post khung data using .post() method by obatambeienwasirherbal.com

jQuery post size data using .post() method

Fill out & submit the form below to lớn get response.
<đầu vào type="text" name="firstname" placeholder="Firstname" />
<đầu vào type="text" name="lastname" placeholder="Lastname" />

3. jQuery post JSON data using .post() method

Sometimes you don’t want to lớn post data from an HTML form. You can bởi vì it by creating a JSON string, & here’s how you’ll be able to post it.

jQuery post JSON data using .post() method by obatambeienwasirherbal.com

jQuery post JSON data using .post() method

Clichồng the button below to lớn get response.
<đầu vào type="button" value="Post JSON" id="postJson" />

Posting a JSON string using the .ajax() method is also possible, you can just replace the serialize() part with your JSON string.

Posted Data

Where did the posted data go? To the file where you want the posted data khổng lồ be processed! But in our example, we just print the posted data. post_receiver.php has the following code

"; print_r($_POST); echo ""; ?>

Download Source Code You can download all the code used in this tutorial for only $9.99 $5.55!
$5.55 – Download Now Checkout Added lớn cart

If you want to lớn learn how khổng lồ create, read, update and delete data with AJAX, go ahead and learn from our AJAX CRUD Tutorial Using jQuery, JSON and PHP – Step by Step Guide!.

Related Tutorials


GETTING STARTED Learn the basics of web programming. How to lớn Run a PHP Script? JavaScript Tutorial for Beginners Bootstrap Tutorial for Beginners