Home > Article > Web Front-end > jquery$.get() method
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"> $('button').click(function(){ //1.单向传递数据: 客户端直接向服务器请求数据 var url = 'api/data.php' var success = function(res) { $('div').html(res) } $.get(url, success) //2.双向传递: 客户端带上查询参数向服务器请求数据 var url = 'api/data.php' // var data = 'name=site' // var data = 'name=domain' var data = { // 'name': 'site' 'name': 'domain' // 'name': 'hello' } var success = function(res) { $('div').html(res) } $.get(url, data, success) }) </script>
The above is the detailed content of jquery$.get() method. For more information, please follow other related articles on the PHP Chinese website!