A Pen by liuxiaomingskm on CodePen.
Last active
February 2, 2020 00:01
-
-
Save liuxiaomingskm/40a40ad05e67cf2e13357f3b1403346e to your computer and use it in GitHub Desktop.
jQuery AJAX Shorthand Methods(JQuery发送POST、PUT、getJSON的快捷写法)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script | |
src="https://code.jquery.com/jquery-3.2.1.min.js"></script> | |
<button id="getBtn">GET()</button> | |
<button id="postBtn">POST()</button> | |
<button id="getJSONBtn">GETJSON()</button> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$("#getBtn").click(function(){ | |
$.get("https://api.github.com/users/colt") | |
.done(function(data){ | |
console.log(data); | |
}) | |
.fail(function(){ | |
console.log("ERROR!"); | |
}) | |
}); | |
$("#postBtn").click(function(){ | |
var data = {name: "Charlie", city: "Florence"}; | |
$.post("www.catsarecoolandsoaredogs.com", data) | |
.done(function(data){ | |
console.log("HI!"); | |
}) | |
.fail(function(){ | |
console.log("ERROR!"); | |
}) | |
}); | |
$("#getJSONBtn").click(function(){ | |
$.getJSON("https://api.github.com/users/colt") | |
.done(function(data){ | |
console.log(data); | |
}) | |
.fail(function(err){ | |
console.log(err); | |
}) | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment