JQueryJsonForm.jsp


Dosyayı İndir
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <script src="../../js/jquery-1.10.2.min.js"></script>
  </head>
  <body>
    <form>
      Ürün No : 
      <input id="productId" type="text"/>
      <br/>  <br/>
      Ürün Adı : 
      <input id="productName" type="text"/>
      <br/> <br/>
      Satış Fiyatı : 
      <input id="salesPrice" type="text"/>
      <br/> <br/>
      <button id="jsonget" type="button" >Getir</button>
      &nbsp;
      <button id="jsonpost" type="button" >Gönder</button>
    </form>
  </body>
  <script>
    var resourceUrl="http://localhost:8080/RestfulServiceDefinitions/myapplication/myresource";
    $("#jsonget").click(function() {
      alert("Getir düğmesine basıldı");
      $.getJSON(resourceUrl,
              function(data) {
                alert("Sonuç geldi");
                $.each(data, function(property, value) {
                  alert(property + "=" + value);
                  if (property === "productId") {
                    $("#productId").val(value);
                  } else if (property === "productName") {
                    $("#productName").val(value);
                  } else if (property === "salesPrice") {
                    $("#salesPrice").val(value);
                  }
                });
              });
    });
    $("#jsonpost").click(function() {
      alert("Gönder düğmesine basıldı");
      $.ajax({
        url: resourceUrl,
        type: "PUT",
        contentType: "application/json",
        data: JSON.stringify({
          "productId": parseInt($("#productId").val()),
          "productName": $("#productName").val(),
          "salesPrice": parseFloat($("#salesPrice").val())
        }),
        dataType: "json",
        success: function() {
          alert("JSON başarıyla gönderildi ");
        },
        error: function(xhr, ajaxOptions, thrownError) {
          alert("JSON gönderme hatası " + xhr.status
                  + " " + thrownError + " " + ajaxOptions);
        }
      });
    });
  </script>
</html>

				
Dosyayı İndir

Bu Sayfayı Paylaş:




Bu Sayfayı Paylaş:

İletişim Bilgileri

Takip Et

Her Hakkı Saklıdır. Bu sitede yayınlanan tüm bilgi ve fikirlerin kullanımından fibiler.com sorumlu değildir. Bu sitede üretilmiş , derlenmiş içerikleri, fibiler.com'u kaynak göstermek koşuluyla kendi sitenizde kullanılabilirsiniz. Ancak telif hakkı olan içeriklerin hakları sahiplerine aittir