When page load first time the page contents which are I load on Jquery.ready javascripts work perfect then when I use ajax to do some things and try to load page again javascript are not working on that second page which I try to load. I tried to solve this problem by using live()
/ on()
methods but it didn't work.
$(document).ready(function () {
$("#grupyonetimarea").load("/Panel/MusteriSourcePages/mus_grup_add.aspx");
});
$('#btnekleme').live('click', function () {
$.ajax({
type: "POST",
url: "/Panel/MusteriSource/mus_kisiadd.aspx/mus_kisi_kaydet",
data: "{ad:'" + $.trim($("#txtalt_mus_adi").val()) + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
cache: false,
before: $("#btnekleme").hide(),
success: function (msg) {
if (msg.d == "ok") {
$("#grupyonetimarea").load("/Panel/MusteriSourcePages/mus_grup_add.aspx");
} else $("#loaded").html(msg.d).show(500);
},
error: function (x, e) {
alert("The call to the server side failed. " + x.responseText);
}
});
}
live
is deprecated so use on()
delegated event.. delegate it to closest static parent.. ( this might not be the issue but its safe to use on() for future if incase you want to update your jquery in near future...)..here is the link if you want to read more about on()
$(document).on('click','#btnekleme', function () {.. //using closest static parent element is preferred here than the document
and you can send data as object in ajax
var inputValue= $.trim($("#txtalt_mus_adi").val());
data: {ad:inputValue},