Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function translate() {
- var word = $("#prodId").val();
- $.getJSON("api/translation?word=" + word,
- function (data) {
- $("#word").text(data.TranslatedWord);
- })
- .fail(
- function (jqXHR, textStatus, err) {
- $("#word").text('Error: ' + err);
- });
- }
- function find() {
- var id = $("#prodId").val();
- $.getJSON("api/products/" + id,
- function (data) {
- var str = data.Name + ': $' + data.Price;
- $("#product").text(str);
- })
- .fail(
- function (jqXHR, textStatus, err) {
- $("#product").text('Error: ' + err);
- });
- }
- <div id="body">
- <div class="main-content">
- <div>
- <h1>All Products</h1>
- <ul id="products" />
- </div>
- <div>
- <label for="prodId">ID:</label>
- <input type="text" id="prodId" />
- <input type="button" value="Translate" onclick="translate();" />
- <p id="word" />
- </div>
- </div>
- </div>
- <script type="text/javascript">
- $(document).ready(function () {
- // Send an AJAX request
- $.getJSON("api/products/",
- function (data) {
- // On success, 'data' contains a list of products.
- $.each(data, function (key, val) {
- // Format the text to display.
- var str = val.Name + ': $' + val.Price;
- // Add a list item for the product.
- $('<li/>', { text: str })
- .appendTo($('#products'));
- });
- });
- });
- function find() {
- var id = $("#prodId").val();
- $.getJSON("api/products/" + id,
- function (data) {
- var str = data.Name + ': $' + data.Price;
- $("#product").text(str);
- })
- .fail(
- function (jqXHR, textStatus, err) {
- $("#product").text('Error: ' + err);
- });
- }
- function translate() {
- var word = $("#prodId").val();
- $.getJSON("api/translation?word=" + word,
- function (data) {
- $("#word").text(data.TranslatedWord);
- })
- .fail(
- function (jqXHR, textStatus, err) {
- console.log(err);
- $("#word").text('Error: ' + err);
- });
- }
- </script>
- $("#translateButton").click(function() {
- translate();
- });
- <input id="translateButton" type="button" value="Translate" />
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement