Home > Web Front-end > JS Tutorial > jquery$.get() method

jquery$.get() method

无忌哥哥
Release: 2018-06-29 15:11:21
Original
6142 people have browsed it

jquery $.get method to get data

* $.get(url,data,success)

* Function: Get data asynchronously from the server

* Parameters: url requested server processing script or data source

* data data sent to the server, usually query string

* success callback processing function to obtain success

* Mode:

* 1. One-way: only obtain data

* 2. Two-way: return the specified data after querying according to the conditions provided by the client

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>jquery $.get()</title>
</head>
<body>
<div></div>
<button>获取数据</button>
</body>
</html>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
$(&#39;button&#39;).click(function(){
//1.单向传递数据: 客户端直接向服务器请求数据
var url = &#39;api/data.php&#39;
var success = function(res) {
$(&#39;div&#39;).html(res)
}
$.get(url, success)
//2.双向传递: 客户端带上查询参数向服务器请求数据
var url = &#39;api/data.php&#39;
// var data = &#39;name=site&#39;
// var data = &#39;name=domain&#39;
var data = {
// &#39;name&#39;: &#39;site&#39;
&#39;name&#39;: &#39;domain&#39;
// &#39;name&#39;: &#39;hello&#39;
}
var success = function(res) {
$(&#39;div&#39;).html(res)
}
$.get(url, data, success)
})
</script>
Copy after login

The above is the detailed content of jquery$.get() method. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template