tags:

views:

56

answers:

4

I have the following JSON call, the data I'm passing seems to be getting stringify'ed properly from what i'm looking at, however, I don't seem to have the right syntax to process the parameter in the public web method.

Here is the JSON call:

<script type="text/javascript" language="javascript"> 

  var qs = new Querystring();

  var v1 = qs.get("TorVName");

  var jsonData = JSON.stringify(v1);  

        $().ready(function() {
            $.ajax({
                type: "POST",
                url: "Default.aspx/GetColumns",
                data: jsonData,
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(msg) {
       var optString = '<option value="-1">Select Column</option>';
        $.each(msg.d, function(index, item) {
        optString += '<option value="' + item + '">' + item + '</option>';
        });
        $('select[name^=DDLColumns]').html(optString);
                },
                error: function() {
                    alert("Failed to load columns");
                }
            });
        });
</script>

and here is the cooresponding web method:

    [WebMethod]
    public static ArrayList GetColumns(string TorVName)
    {
        String cnstr = "myconnect string";
        string Sql = String.Empty;
        ArrayList arlist = new ArrayList();
        SqlDataReader rdr = null;
        SqlCommand cmd = null;
        DataSet dset;
        SqlConnection cn = new SqlConnection(cnstr);
        cn.Open();
        dset = new DataSet("ds");
        dset.Clear();

etc etc...

I have a hard time deciding how to debug a web method since I can only see the client side actions in firebug.

any help on how to recieve and process the parameter in the web method would be most appreciated.

Thanks Deano

A: 

You need to attach Visual Studio to the w3wp.exe that is running your web app and put a breakpoint.

The other possibility is to put a System.Net tracing to output all data coming in and out of application:

http://blogs.msdn.com/b/dgorti/archive/2005/09/18/471003.aspx

Put the stuff in the web.config.

Aliostad
A: 

Your data needs to be in name/value pair format, like this:

 var jsonData = JSON.stringify({ TorVName: qs.get("TorVName") }); 

The web method is looking for the property named TorVName, so you need a name/value pair with this for your JSON request, not just the string. In the above code the TorVName: is because that's what the parameter is named in the web method.

Nick Craver
A: 

as others have stated, you need ot have a json object with a parameter of torVName since htat is what your web method is looking for. an easy way to do this is var data={};//create new object data['torVName']=actual datta'; then in your ajax call you can just say data:JSON.stringify(data)

Chris Westbrook
A: 

maybe you guys should read this before suggesting the stringify stuff in IE8:

JSON returns 'undefined' when stringifying an object that was created in a different window See test case at http://kinsey.no/examples/ie8_json_bug/

Lyle