﻿
{"id":4491,"date":"2016-06-20T08:51:22","date_gmt":"2016-06-20T08:51:22","guid":{"rendered":"http:\/\/www.gencayyildiz.com\/blog\/?p=4491"},"modified":"2016-06-20T08:51:22","modified_gmt":"2016-06-20T08:51:22","slug":"asp-net-mvcde-getjson-ile-get-islemi","status":"publish","type":"post","link":"https:\/\/www.gencayyildiz.com\/blog\/asp-net-mvcde-getjson-ile-get-islemi\/","title":{"rendered":"Asp.NET MVC&#8217;de getJSON \u0130le Get \u0130\u015flemi"},"content":{"rendered":"<div id=\"fb-root\"><\/div>\n<p>Merhaba,<\/p>\n<p>Asp.NET MVC&#8217;de Ajax ile post i\u015fleminin yan\u0131nda ayriyetten get i\u015flemide olmazsa olmaz bir talep se\u00e7ene\u011fidir. Haliyle gelin \u015fimdi bu i\u00e7erikte jQuery k\u00fct\u00fcphanesi e\u015fli\u011finde Asp.NET MVC mimarisinde nas\u0131l Get i\u015flemi ger\u00e7ekle\u015ftiriliyor detayl\u0131ca inceleyelim.<\/p>\n<p>\u00d6ncelikle jQuery k\u00fct\u00fcphanesinin en k\u00f6t\u00fc 1.0 versiyonunu projenize entegre etmeniz kafidir.<\/p>\n<p>\u015eimdi a\u015fa\u011f\u0131daki prototipe g\u00f6z at\u0131n\u0131z.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n            $.ajax({\r\n                url: 'GET Adres',\r\n                dataType: 'json',\r\n                data: { Parametre: 'Deger' },\r\n                success: function (data) {\r\n                    \/\/\u0130\u015flemler...\r\n                }\r\n            });\r\n<\/pre>\n<p>G\u00f6rd\u00fc\u011f\u00fcn\u00fcz gibi post i\u015fleminden tek fark\u0131 <strong><em>type: &#8216;POST&#8217;<\/em><\/strong> parametresinin olmamas\u0131d\u0131r. Asl\u0131nda bu \u015fekilde bir kullan\u0131mda varsay\u0131lan olarak <strong><em>type: &#8216;GET&#8217;<\/em><\/strong> ifadesi hakimdir. Tabi ki de siz isterseniz <strong><em>type: &#8216;GET&#8217;<\/em><\/strong> parametresinide kullanabilirsiniz.<\/p>\n<p>Elimizde a\u015fa\u011f\u0131daki gibi bir Controller olsun.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    public class HomeController : Controller\r\n    {\r\n        \/\/ GET: Home\r\n        public ActionResult Index()\r\n        {\r\n            return View();\r\n        }\r\n\r\n        &#x5B;HttpGet]\r\n        public JsonResult GetMethod(int? x)\r\n        {\r\n            return Json(x.ToString(), JsonRequestBehavior.AllowGet);\r\n        }\r\n    }\r\n<\/pre>\n<p>&#8220;Index.cshtml&#8221; \u00fczerinden &#8220;GetMethod&#8221; isimli Action metoda bir GET i\u015flemi ger\u00e7ekle\u015ftirelim.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n&lt;input type=&quot;submit&quot; value=&quot;Post Et&quot; id=&quot;btnPost&quot; \/&gt;\r\n\r\n&lt;script type=&quot;text\/javascript&quot;&gt;\r\n    $(document).ready(function () {\r\n        $(&quot;#btnPost&quot;).click(function () {\r\n            $.ajax({\r\n                url: '@Url.Action(&quot;GetMethod&quot;,&quot;Home&quot;)',\r\n                dataType: 'json',\r\n                data: { x: 3 },\r\n                success: function (data) {\r\n                    alert(data + ' verisi gelmi\u015ftir.');\r\n                }\r\n            });\r\n        });\r\n    });\r\n&lt;\/script&gt;\r\n<\/pre>\n<p>Bu i\u015flem neticesinde butona t\u0131kland\u0131\u011f\u0131 zaman a\u015fa\u011f\u0131daki sonucu elde etmekteyiz.<br \/>\n<a href=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2016\/06\/Asp.NET-MVCde-getJSON-\u0130le-Get-\u0130\u015flemi.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2016\/06\/Asp.NET-MVCde-getJSON-\u0130le-Get-\u0130\u015flemi.jpg\" alt=\"Asp.NET MVC&#039;de getJSON \u0130le Get \u0130\u015flemi\" width=\"193\" height=\"85\" class=\"aligncenter size-full wp-image-4494\" \/><\/a><\/p>\n<p>\u015euana kadar getJSON fonksiyonuna de\u011finmeden olay\u0131n nas\u0131l ajax componenti \u00fczerinden ger\u00e7ekle\u015ftirildi\u011fini incelemi\u015f olduk. Haliyle \u015fimdi getJSON fonksiyonunun prototipini inceleyelim ve ard\u0131ndan ayn\u0131 i\u015flemleri ger\u00e7ekle\u015ftirelim.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n            $.getJSON('url', function (data) {\r\n                \/\/\u0130\u015flemler...\r\n            });\r\n<\/pre>\n<p>G\u00f6rd\u00fc\u011f\u00fcn\u00fcz gibi bu fonksiyon sayesinde verilen url&#8217;e GET i\u015flemi uygulanmakta ve geriye d\u00f6n\u00fclen sonucu JSON format\u0131nda data parametresiyle elde etmekteyiz.<\/p>\n<p>Ayriyetten done, fail ve always fonksiyonlar\u0131da a\u015fa\u011f\u0131daki niyetlerle kullan\u0131labilmektedir.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n            $.getJSON('url', function (data) {\r\n                \/\/\u0130\u015flemler...\r\n            }).done(function () {\r\n                \/\/getJSON talebi ba\u015far\u0131l\u0131ysa buras\u0131 tetiklenecektir.\r\n            }).fail(function (jqXHR, textStatus, errorThrown) {\r\n                \/\/getJSON talebi hatal\u0131ysa buras\u0131 tetiklenecektir.\r\n            }).always(function () {\r\n                \/\/getJSON talebi sonland\u0131ysa buras\u0131 tetiklenecektir.\r\n            });\r\n<\/pre>\n<p>Son olarak parametre alan prototipimizde a\u015fa\u011f\u0131daki gibidir&#8230;<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n            $.getJSON('url', { parametre: &quot;de\u011fer&quot; }, function (data) {\r\n                \/\/\u0130\u015flemler...\r\n            });\r\n<\/pre>\n<p>Ve \u015fimdide yukar\u0131daki yapt\u0131\u011f\u0131m\u0131z \u00f6rnek GET i\u015fleminin ayn\u0131s\u0131n\u0131 getJSON fonksiyonu ile ger\u00e7ekle\u015ftirelim.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n&lt;input type=&quot;submit&quot; value=&quot;Post Et&quot; id=&quot;btnPost&quot; \/&gt;\r\n\r\n&lt;script type=&quot;text\/javascript&quot;&gt;\r\n    $(document).ready(function () {\r\n        $(&quot;#btnPost&quot;).click(function () {\r\n            $.getJSON('@Url.Action(&quot;GetMethod&quot;, &quot;Home&quot;)', { x: 123 }, function (data) {\r\n                alert(data + ' verisi gelmi\u015ftir.');\r\n            });\r\n        });\r\n    });\r\n&lt;\/script&gt;\r\n<\/pre>\n<p>Sonraki yaz\u0131lar\u0131mda g\u00f6r\u00fc\u015fmek dile\u011fiyle&#8230;<br \/>\n\u0130yi \u00e7al\u0131\u015fmalar dilerim&#8230;<\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>Merhaba, Asp.NET MVC&#8217;de Ajax ile post i\u015fleminin yan\u0131nda ayriyetten get i\u015flemide olmazsa olmaz bir talep se\u00e7ene\u011fidir. Haliyle gelin \u015fimdi bu i\u00e7erikte jQuery k\u00fct\u00fcphanesi e\u015fli\u011finde Asp.NET MVC mimarisinde nas\u0131l Get i\u015flemi ger\u00e7ekle\u015ftiriliyor detayl\u0131ca inceleyelim. \u00d6ncelikle&#46;&#46;&#46;<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":3401,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,11,600,19,780],"tags":[854,746,576,853,1241,748,530],"class_list":["post-4491","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-asp-net","category-asp-net-mvc","category-asp-net-mvc-5","category-jquery","category-json","tag-always","tag-asp-net-mvc","tag-done","tag-fail","tag-getjson","tag-jquery","tag-json"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/4491","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/comments?post=4491"}],"version-history":[{"count":0,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/4491\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media\/3401"}],"wp:attachment":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media?parent=4491"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/categories?post=4491"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/tags?post=4491"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}