2014-11-01 110 views
-1

(function(){$('。KisiSilici')。click(function(){ does not working .click,.on,.live,is my try but not work。Thanks for your help 。ajax選擇性不工作

也許是因爲我填寫表格與阿賈克斯

$(document).ready(function Kisilertabs() { 
 
       $(function() { 
 
        $("#tabs").tabs(); 
 
       }); 
 
       var id = @Model.ID.ToString() 
 
       $.ajax({ 
 
        url: '@Url.Action("Kisiler", "Cihazlar")', 
 
        type: "get", 
 
        contentType: "application/json; charset=utf-8", 
 
        data: { data: id }, 
 
        dataType: "json", 
 
        success: function (data) { 
 
         var row = "<tr><th width='70'>S. No</th><th width='220'> Adı </th><th width='220'>Soyadı</th><th>Sicil No</th><hr/></tr>"; 
 
         $.each(data, function (index, item) { 
 
          row += "<tr id='" + item.ID + "'><td>" + item.ID + "</td ><td>" + item.Adi + "</td><td>" + item.Soyadi + "</td><td>" + item.Sicil + "</td><td><a href='/Kullanicilar/Details/" + item.ID + "'><img width='15' src='../../Content/images/Detay.png'></a></td><td><input id='Kisisec' value='" + item.ID + "' class='KisiSilici' type='image' width='20' src='../../content/images/sil.png' /></td></tr><hr />"; 
 
         }); 
 
         $("#Kisiler").html(row); 
 
        }, 
 
        error: function (result) { 
 
         alert("Error"); 
 
        } 
 

 
       }) 
 
      }); 
 
      $(function problem() { 
 
       $('.KisiSilici').click(function() { 
 
        var ip = ""; 
 
        $.ajax({ 
 
         url: '@Url.Action("KisilerSil", "tabs")', 
 
         type: "POST", 
 
         data: { data: ip }, 
 
         success: function (data) { 
 
          var row = "<p>" + data + "</p>"; 
 
          $("#CihazKontrol").prepend(row); 
 
         }, 
 
         error: function (result) { 
 
          alert("Error"); 
 

 
         }, 
 
        }) 
 
       }); 
 
      });

+1

** $(功能問題()**是什麼意思? – 2014-11-01 13:24:30

+1

你能否明白你在問什麼? – 2014-11-01 13:25:36

回答

0

沒有與此代碼幾個問題:

  • $(document).ready(...)$(...)完全一樣,所以在$(document).ready(...)內使用$(...)沒有任何意義。你可以鬆動$(...)環繞。
  • 給予匿名函數的problem給我們一個錯誤。作爲參數的函數都意味着是匿名的,或只是引用(地名)到另一個功能,所以你可以做這樣的:

    $(function() { 
        //do smth 
    }); 
    

或本:

function do(){ 
     //do smth 
    } 
    $(do); 

所以,你的代碼,因爲我看到它,應該看起來更像這樣:(在這裏很難說出你的觀點)

 $(document).ready(function Kisilertabs() { 
      $("#tabs").tabs(); 
      var id = @Model.ID.ToString() 
      $.ajax({ 
       url: '@Url.Action("Kisiler", "Cihazlar")', 
       type: "get", 
       contentType: "application/json; charset=utf-8", 
       data: { data: id }, 
       dataType: "json", 
       success: function (data) { 
        var row = "<tr><th width='70'>S. No</th><th width='220'> Adı </th><th width='220'>Soyadı</th><th>Sicil No</th><hr/></tr>"; 
        $.each(data, function (index, item) { 
         row += "<tr id='" + item.ID + "'><td>" + item.ID + "</td ><td>" + item.Adi + "</td><td>" + item.Soyadi + "</td><td>" + item.Sicil + "</td><td><a href='/Kullanicilar/Details/" + item.ID + "'><img width='15' src='../../Content/images/Detay.png'></a></td><td><input id='Kisisec' value='" + item.ID + "' class='KisiSilici' type='image' width='20' src='../../content/images/sil.png' /></td></tr><hr />"; 
        }); 
        $("#Kisiler").html(row); 
       }, 
       error: function (result) { 
        alert("Error"); 
       } 

      }) 
     }); 

     $('.KisiSilici').click(function() { 
      var ip = ""; 
      $.ajax({ 
       url: '@Url.Action("KisilerSil", "tabs")', 
       type: "POST", 
       data: { data: ip }, 
       success: function (data) { 
        var row = "<p>" + data + "</p>"; 
        $("#CihazKontrol").prepend(row); 
       }, 
       error: function (result) { 
        alert("Error"); 
       }, 
      }); 
     });