jQuery post() get() ajax() Example

10 มิ.ย. 2017 , 5,502 Views   , หมวดหมู่ jQuery,JavaScript,Ajax ทุกหมวดหมู่ โค๊ดดิ้ง   , ป้ายกำกับ:, , ,


ajax()

https://www.w3schools.com/jquery/ajax_ajax.asp
https://api.jquery.com/jquery.ajax/

Syntax

Name Value/Description
async A Boolean value indicating whether the request should be handled asynchronous or not. Default is true
beforeSend(xhr) A function to run before the request is sent
cache A Boolean value indicating whether the browser should cache the requested pages. Default is true
complete(xhr,status) A function to run when the request is finished (after success and error functions)
contentType The content type used when sending data to the server. Default is: “application/x-www-form-urlencoded”
context Specifies the “this” value for all AJAX related callback functions
data Specifies data to be sent to the server
dataFilter(data,type) A function used to handle the raw response data of the XMLHttpRequest
dataType The data type expected of the server response.
error(xhr,status,error) A function to run if the request fails.
global A Boolean value specifying whether or not to trigger global AJAX event handles for the request. Default is true
ifModified A Boolean value specifying whether a request is only successful if the response has changed since the last request. Default is: false.
jsonp A string overriding the callback function in a jsonp request
jsonpCallback Specifies a name for the callback function in a jsonp request
password Specifies a password to be used in an HTTP access authentication request.
processData A Boolean value specifying whether or not data sent with the request should be transformed into a query string. Default is true
scriptCharset Specifies the charset for the request
success(result,status,xhr) A function to be run when the request succeeds
timeout The local timeout (in milliseconds) for the request
traditional A Boolean value specifying whether or not to use the traditional style of param serialization
type Specifies the type of request. (GET or POST)
url Specifies the URL to send the request to. Default is the current page
username Specifies a username to be used in an HTTP access authentication request
xhr A function used for creating the XMLHttpRequest object

post()

https://api.jquery.com/jquery.post/
https://www.w3schools.com/jquery/ajax_post.asp

Syntax

Parameter Description
URL Required. Specifies the url to send the request to
data Optional. Specifies data to send to the server along with the request
function(data,status,xhr) Optional. Specifies a function to run if the request succeeds
Additional parameters:

  • data – contains the resulting data from the request
  • status – contains the status of the request (“success”, “notmodified”, “error”, “timeout”, or “parsererror”)
  • xhr – contains the XMLHttpRequest object
dataType Optional. Specifies the data type expected of the server response.
By default jQuery performs an automatic guess.
Possible types:

  • “xml” – An XML document
  • “html” – HTML as plain text
  • “text” – A plain text string
  • “script” – Runs the response as JavaScript, and returns it as plain text
  • “json” – Runs the response as JSON, and returns a JavaScript object
  • “jsonp” – Loads in a JSON block using JSONP. Will add an “?callback=?” to the URL to specify the callback

get()

https://api.jquery.com/jquery.get/
https://www.w3schools.com/jquery/ajax_get.asp

Syntax

Parameter Description
URL Required. Specifies the URL you wish to request
data Optional. Specifies data to send to the server along with the request
function(data,status,xhr) Optional. Specifies a function to run if the request succeeds
Additional parameters:

  • data – contains the resulting data from the request
  • status – contains the status of the request (“success”, “notmodified”, “error”, “timeout”, or “parsererror”)
  • xhr – contains the XMLHttpRequest object
dataType Optional. Specifies the data type expected of the server response.
By default jQuery performs an automatic guess.
Possible types:

  • “xml” – An XML document
  • “html” – HTML as plain text
  • “text” – A plain text string
  • “script” – Runs the response as JavaScript, and returns it as plain text
  • “json” – Runs the response as JSON, and returns a JavaScript object
  • “jsonp” – Loads in a JSON block using JSONP. Will add an “?callback=?” to the URL to specify the callback

 


ป้ายกำกับ:, , ,