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

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -