tags:

views:

33

answers:

2

hi there.

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?

A: 

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.

James Black
It probably didn't work for you in the aspx because the web method being called *must* be static.
Matt
I think I tried that, and after spending a while on it, I just moved it out of the .aspx file and got it working, so it could return a json and receive everything as json.
James Black
+1  A: 

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);
 }
Matt