Home >Web Front-end >JS Tutorial >The use of ajax post in jquery

The use of ajax post in jquery

伊谢尔伦
伊谢尔伦Original
2016-11-22 14:54:401353browse

jQuery.post(url, [data], [callback], [type])

Overview

Load information via remote HTTP POST request.

This is a simple POST request function to replace the complex $.ajax. The callback function can be called when the request is successful. If you need to execute a function on error, use $.ajax.

Parameters

url,[data],[callback],[type]String,Map,Function,StringV1.0

url: Send request address.

data: Key/value parameters to be sent.

callback: callback function when sending successfully.

type: Return content format, xml, html, script, json, text, _default.

Example

1) Pass an array of data to the server (while still ignoring the return value):

jQuery code:

$.post("test.php", { 'choices[]': ["Jon", "Susan"] });

2) Send form data using ajax request:

jQuery code:

$.post("test.php", $("#testform").serialize());

3) Test the page .php sends data and outputs the result (HTML or XML, depending on the returned content):

jQuery code:

$.post("test.php", { name: "John", time: "2pm" },
   function(data){
     alert("Data Loaded: " + data);
   });

4) Get the content of the test.php page and store it as an XMLHttpResponse object and pass it through process() This JavaScript function is processed:

jQuery code:

$.post("test.php", { name: "John", time: "2pm" },
   function(data){
     process(data);
   }, "xml");

5) Get the json format content returned by the test.php page:

jQuery code:

$.post("test.php", { "func": "getNameAndTime" },
  function(data){
    alert(data.name); // John
    console.log(data.time); //  2pm
  }, "json");


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn