天天看點

jquery+get(.java)方法_jQuery get()方法

jQuery get()方法

get()方法是jQuery中的内置函數。它使用HTTP GET請求從伺服器加載資料。它用于發出簡單的GET請求。它傳回XMLHttpRequest對象。

句法

參數值

此方法包括四個參數值,其中一個是必需的,其他是可選的。我們必須将URL參數包含在get()方法中。下表定義了get()方法的參數值。

Parameter

Values

URL

It is the URL to which the request is sent. It is a mandatory parameter.

data

It is an optional parameter. It is data sent to the server along with the request. It can be a plain object or a string.

function(data, status, xhr)

This is also an optional parameter. It is a callback function that executes on the successful server request.

It also has three parameters that are data, status, and xhr in which data contains the resulting data from the request, status represents the request status like “success”, “error”, etc., and the xhr contains the XMLHttpRequest object.

dataType

This is also an optional parameter that defines the type of data we are expecting from the server. The type can be “text”, “json”, “jsonp”, “html”, “script”, and “XML”.

現在,讓我們看一個使用get()方法的簡單示例。

在此示例中,我們通過使用get()方法發出一個get請求。我們使用get()方法的兩個參數,即URL和回調函數。

URL參數設定為值test.html。我們使用回調函數的兩個參數,分别是data和status,其中第一個參數儲存請求頁面的資料,第二個參數儲存請求狀态。

在輸出中,我們可以看到從伺服器加載的資料,并且請求的狀态為成功。

test.html

Example2.html

輸出量

執行完上述代碼後,輸出将為-

jquery+get(.java)方法_jQuery get()方法

點選給定的按鈕後,輸出将是-

jquery+get(.java)方法_jQuery get()方法

相關文章:jQuery-選擇器 jQuery-選擇器 jQuery庫利& […]...

jQuery-Whatsnearby.js jQuery-Whatsnearby.js Whatsnearby.js是一 […]...

jQuery選擇器 jQuery選擇器 jQuery選擇器用于選擇和操作HTML元素。它們是jQuery庫的重要組成部分。 使用j […]...

jQuery before() jQuery before() jQuery before()方法用于将指定的内容插入所選元素之前。它将參數指 […]...

jQuery addClass() jQuery addClass() addclass()方法用于将一個或多個類名稱添加到所選元素。此方法僅用于 […]...

jQuery unWrap() jQuery unwrap() jQuery unwrap()方法用于删除所選元素的父元素。 句法:...

jQuery keydown() jQuery keydown() 當您按下鍵盤上的一個鍵時,會發生keydown()事件,并且一旦發生keyd […]...

jQuery Extend()方法 jQuery extend()方法 jQueryextend()方法将兩個或更多對象的内容合并到第一個對象中。 […]...