An get of method usage instance of ajax in jQuery

  • 2020-05-10 17:36:58
  • OfStack

This article illustrates the use of the get() method for ajax in jQuery as an example. Share with you for your reference. The specific analysis is as follows:

$.get () requests data from the server via the HTTP GET request.

Grammatical structure:

$.get(url, [data], [callback], [type]);

Parameter analysis:

1.URL: must, specify the requested URL.
2.data: optional, to be sent Key/value parameters.
3.callback: optional callback function to be executed upon successful request.
4.type: optional, return content format, xml, html, script, json, text, _default.

Code example:


<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="//www.ofstack.com/" />
<title> The home of the script </title>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("#bt").click(function(){
    $.get("mytest/demo/antzone.txt",function(data,status){
      alert("Data:"+data+"\nStatus:"+status);
    })
  })
})
</script>
</head>
<body>
<input type="button" value=" See the effect " id="bt"/>
</body>
</html>

I hope this article has been helpful to your jQuery programming.


Related articles: