开发者

Can't call page method from JQuery?

I have a开发者_StackOverflow page called AddNews.aspx and in codebehind a web method called AddNews(Parameters)..

AddNews.aspx page is inherited from a master page.. So i used contentplaceholder.

I have a button..It's id is btnSave.

Here is jquery code:

$(function() {
 $("[id$='_btnSave']").click(function() {
  $.ajax({
    type: "POST",
    contentType: "application/json; charset=utf-8",
    data: $.toJSON(veriler),
    url: "AddNews.aspx/AddNews",
    dataType: "json",
    success: function(result) {
      $("#result").html('News added');
    },
    error: function() {
      alert('Problem');
    }
  });
 });
});
</script>

Button click trigger now.. But it doesnt call Web Page Method.. What's the problem?


Does your page method look similar to this: (c# assumed here) IF you have parameters (you say so) the names need to match exactly the ajax part.

[WebMethod]
        public static string GetServerTimeString()
        {
            return "Current Server Time: " + DateTime.Now.ToString();
        }

EDIT: you can reference my answer to this question for a page method with parameters: Jquery .ajax async postback on C# UserControl

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜