当第一次加载页面时,我在Jquery.ready javascripts上加载的页面内容工作完美,那么当我使用ajax做一些事情并尝试再次加载页面时,javascript无法在我尝试加载的第二页上运行。我尝试使用live()
/ on()
方法解决此问题,但它无效。
$(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);
}
});
}
答案 0 :(得分:1)
live
已被弃用,因此请使用on()
委托事件..将其委托给最近的静态父..(这可能不是问题,但如果你想要,可以安全地使用on()作为未来在不久的将来更新您的jquery ...)..如果您想了解更多关于on()
$(document).on('click','#btnekleme', function () {.. //using closest static parent element is preferred here than the document
您可以在ajax中将对象作为对象发送
var inputValue= $.trim($("#txtalt_mus_adi").val());
data: {ad:inputValue},
答案 1 :(得分:0)
非常感谢你的所有答案。我是这样做的,我刚刚创建了一个kontrolet()函数,当我运行这个dunction时,它的工作效果很好。
$(document).on('click', '#btnekleme', function () {
$("#grupyonetimarea").load("/Panel/MusteriSourcePages/mus_grup_add.aspx");
});
function kontrolet() {
$.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");
alert("Kayıt işlemi başarılıdır.!");
TextArealariClearET();
$("#btnekleme").show();
}
else
$("#loaded").html(msg.d).show(500);
},
error: function (x, e) {
alert("The call to the server side failed. " + x.responseText);
}
});
}