Created
December 2, 2015 14:19
-
-
Save nonZero/ed3a36bf6f17c3c4466b to your computer and use it in GitHub Desktop.
simple ajax demo
This file contains hidden or 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
$(function () { | |
"use strict"; | |
$("#update-btn").click(function () { | |
var el = $(this); | |
if (el.attr("disabled")) { | |
return; | |
} | |
var url = el.data("url"); | |
el.attr('disabled', "true"); | |
$("#rate").load(url, function (respText, status, xhr) { | |
if (status == "error") { | |
$("#rate").css('background', 'red'); | |
} | |
el.removeAttr('disabled'); | |
}).text("?").css('background', ''); | |
console.log("clicked!"); | |
}); | |
$("#update-cart").click(function () { | |
var el = $(this); | |
if (el.attr("disabled")) { | |
return; | |
} | |
var url = el.data("url"); | |
el.attr('disabled', "true"); | |
$.get(url) | |
.success(function (data) { | |
$.each(data.items, function (i, item) { | |
$("<li>").text(item).appendTo($("#items")); | |
}); | |
$("#total").text(data.total); | |
}) | |
.error(function () { | |
alert("something went wrong"); | |
}); | |
console.log("clicked!"); | |
}); | |
$("#send").click(function () { | |
var el = $(this); | |
if (el.attr("disabled")) { | |
return; | |
} | |
var url = el.data("url"); | |
el.attr('disabled', "true"); | |
$.post(url, {text: $("#foo").val()}) | |
.success(function (data) { | |
alert("ok"); | |
}) | |
.error(function () { | |
alert("NOT OK"); | |
}); | |
console.log("clicked!"); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment