javascript - AJAX code for calling code-behind method from aspx page doesn't work -
upon click of anchor link, want call code-behind function (which loads html content code page).
the code-behind:
public void loadnewpage(string id) { ltlcontent.text = getpagecenter(id); }
the js code:
$('a').click(function (e) { e.preventdefault(); var data = { username: $(this).attr("id") }; var dataval = json.stringify(data); $.ajax({ type: "post", url: "default.aspx/loadnewpage()", contenttype: "application/json; charset=utf-8", data: dataval, datatype: "json", success: function (id) { } }); });
html:
<a href="#" id="kontakt">go kontakt</a>
what #
being added @ of url , code-behind function not called.
try this:
in anchor this:
<a href="javascript:void(0)" id="kontakt">go kontakt</a>
and modify ajax script this:
$('a').click(function (e) { var data = { 'id': $(this).attr("id") }; var dataval = json.stringify(data); $.ajax({ type: "post", url: "default.aspx/loadnewpage", contenttype: "application/json; charset=utf-8", data: dataval, datatype: "json", success: function (id) { } }); });
Comments
Post a Comment