All TalkersCode Topics

Follow TalkersCode On Social Media

devloprr.com - A Social Media Network for developers Join Now ➔

jQuery Ajax Post Data Example

Last Updated : Mar 11, 2024

jQuery Ajax Post Data Example

In this article we will show the solution of jQuery ajax post data example, a POST method, however, does not cache data, and it is often used to send data along with a request.

A POST HTTP request is used to load a page from the server using jQuery.post( url, [data], [callback], [type]). XMLHttpRequest is the object returned by the method.

An URL string can be used to represent the URL of the request. The data parameter represents key/value pairs or the return value from the function called serialize().

An optional argument denotes a function that should be performed in the event that data loading is successful.

It represents the type of data returned to the callback function: "xml", "html", "script", "json", "jsonp", or "text".

Step By Step Guide On jQuery Ajax Post Data Example :-

<html>
   <head>
      <title>TalkersCode jQuery Example</title>
      <script type = "text/javascript"
         src = "https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js">
      </script>
      <script type = "text/javascript" language = "javascript">
         $(document).ready(function() {
            $("#driver").click(function(event){
               $.post(
                  "result.php",
                  { name: "Maggi" },
                  function(data) {
                     $('#stage').html(data);
                  }
               );
            });
         });
      </script>
   </head>
   <body>
      <p>TalkersCode</p>
      <div id = "stage" style = "background-color:cc0;">
         TalkersCode
</div>
      <input type = "button" id = "driver" value = "Load Data" />
   </body>
</html>
  1. Our first step is to write <HTML>, which tells the browser what version of HTML we're using. HTML documents contain tags as their first element.
  2. The project's heading must be described using the head> tag. Titles and final brackets differ from final brackets because they are both open, rather than closed.
  3. The <script> tag was then added. The script tag also includes the javascript google API run or an explanation of the code or file we used.
  4. The script is then closed and head closed.
  5. Then again we open the <script> tag and then add. The script tag also includes the javascript google API run or an explanation of the code or file we used.
  6. The <body> tag follows, which describes the content of the webpage.
  7. Our next step is to create a paragraph and then to set the color for the background.
  8. Then we create a button.
  9. After that we closed program using </body></html>

Conclusion :-

The GET and POST methods are the most common request-response methods between a client and server.

Data is requested from a specified resource using the GET method.

PUSH - Sends data to be processed to a specified resource, Data can be obtained from a server using GET (get-retrieve). Data may be cached when using the GET method.

I hope this article on jQuery ajax post data example helps you and the steps and method mentioned above are easy to follow and implement.

Author Image About Riya

A recent graduate with a Bachelor of Technology (B.Tech) in Computer Science from India. She is passionate about leveraging technology to solve real-world problems. With a strong foundation and experience in programming languages such as Python, Django, HTML, CSS, and JavaScript, java, php and have honed her skills through hands-on projects and coursework.

Follow Riya On Linkedin 🡪