开发者

How can i post same page with ajax json

this is my ajax post code on Default.aspx's source side:

开发者_开发百科 $.ajax({
            type: "POST",
            url: "Default.aspx/f_Bul,
            data: "{_sSKodu:'4'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(msg) {

                $("#" + div).html(msg.d);
                $("#" + div).show();
            }
        }
        )

and this is my function which is on the Default.aspx.cs

 protected void f_Bul(string _sSKodu)
    {
      Select s = new Select(_sSKodu);
    }

I want send parameter to f_Bul. but i cant post that data.

where is my mistake?


You need to decorate your method with the [WebMethod] attribute, and it must be static. It might have to be public and return a string as well, not 100% on that though.

 [WebMethod]
 public static string f_Bul(string _sSKodu)
 {
      Select s = new Select(_sSKodu);
 }


I couldn't get it to work with .aspx, so I went to .asmx and this is how I finally got it ot work:

   [System.Web.Script.Services.ScriptService]
    public class getData : System.Web.Services.WebService
    {
        [WebMethod]
        [ScriptMethod(UseHttpGet = false, ResponseFormat = ResponseFormat.Json)]
        public string finalize(String Number)
        {
            return "{'result':'success'}";
        }
    }

I also had to put a script manager on my .aspx page, but it finally worked.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜