Trending October 2023 # A Quick Glance On Jquery Post With Examples # Suggested November 2023 # Top 14 Popular |

Trending October 2023 # A Quick Glance On Jquery Post With Examples # Suggested November 2023 # Top 14 Popular

You are reading the article A Quick Glance On Jquery Post With Examples updated in October 2023 on the website We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested November 2023 A Quick Glance On Jquery Post With Examples

Introduction to jQuery post

jQuery post method requests data from the server using HTTP post request. This method sends an asynchronous request to the server to submit the data to the server and get the response. method returns an XML HTTP request object. This method is an AJAX method and is used to call server pages like .aspx or .php. POST method is identical to GET method in jQuery, using $.get() or $.post(), depends on the server-side requirements. In case of a large amount of data being transmitted, for ex., form data, a POST request is to be used instead of a GET request as GET has a strict limit on data transfer to and fro on the server.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Syntax url [, data ] [, success ] [, dataType ] ) Parameters

1. url: Required parameter with data type String containing the request URL to which the request has to be sent or request from where data has to be received.

2. data: JSON data, which as to be sent to the server. An optional parameter with data type as Plain Object or a String that is sent to the server with the request url.

3. success: It is an optional parameter, a callback function which is executed if the request method succeeds or when data is loaded successfully.

Mandatory parameter if dataType is provided, but can also take null value in such cases. Can also be written a function(data, status,xhr), data contains the resulting data, status contains the status of the request processed; may it be a timeout, success, parsing error, etc., and xhr contains the XMLHttpRequest object.

4. dataType: It is an optional parameter and represents the type of data(string) to be returned as a callback function; response can be in the form of xml, script, json, html, jsonp or text.

XML being an XML document.

The script runs as JavaScript and returns plain text.

JSON runs as JSON and returns a JavaScript object.

HTML, plain text.

In a simple format, jQuery post syntax can also be written as:

$.post( URL, data, callback);

Let us see How this jQuery method used?

jQuery script has to be used while implementing, i.e., can be of any version:

Examples of jQuery post

Given below are the examples mentioned:

Example #1


<script type=”text/javascript” $(document).ready(function () { $.post(‘/jquery/submitData’, { myData: ‘Data has been sent successfully using jQuery POST’ }, function(data, status, jqXHR) { $(‘p’).append(‘sent status: ‘ + status + ‘, data sent: ‘ + data); }); }); });


Example #2

jQuery post method.


label{ display: block; margin-bottom: 15px; color: red } $(document).ready(function(){ $(“form”).submit(function(eventObj){ eventObj.preventDefault(); var actionBtn = $(this).attr(“action”); var formValue = $(this).serialize(); $.post(actionBtn, formValue, function(empdata){ $(“#resultData”).html(empdata); }); }); }); In empComment.php <?php $name = htmlspecialchars($_POST[“empname”]);


On entering values:

On submitting:

Example #3

$(document).ready(function(){ $(“form”).on(“submit”, function(eventObj){ eventObj.preventDefault(); var htmlFormValues= $(this).serialize(); var submitAction = $(this).attr(“action”); $.post(submitAction, htmlFormValues, function(formData){ $(“#formResult”).html(formData); }); }); }); In formProcess.php


On entering the details here:

GET method is used to get the data from any URL specified.


We have seen how it works, and its syntax in various forms explained all the required and optional parameters above. Examples solved here will give you an overview of how it is used to send the data to any of the files specified. A good example of Submitting a Form data is shown, which sends its data to a php file and displays the data sent to the file.

Recommended Articles

This is a guide to jQuery post. Here we discuss the introduction to jQuery post along with examples for better understanding. You may also have a look at the following articles to learn more –

You're reading A Quick Glance On Jquery Post With Examples

Update the detailed information about A Quick Glance On Jquery Post With Examples on the website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!