1

I am trying to figure out how to get the parameters that are passed in the URL from a jQuery plugin that I am using. Basically, I'm sending a POST ajax request to my web service and trying to use the URL parameters, but they are always returned as nothing. I'm assuming this has to do with the fact that I'm in a POST.

Can anyone please provide some insight for me on how to accomplish this?

1
  • Can you provide a code sample? Commented Apr 10, 2009 at 22:45

6 Answers 6

1

I'm unsure why you're choosing to use querystring parameters on an AJAX call. Unless there's a very specific reason, you should just post them as parameters to your web service method instead.

Sign up to request clarification or add additional context in comments.

Comments

0

If you're using asp.net WebForms, I recommend using the ScriptManager to generate a javascript proxy to your web-service, and then use that javascript proxy instead of manually doing an ajax call. Here's a quick tutorial/walk-through on using ScriptManager with web services: http://msdn.microsoft.com/en-us/magazine/cc163354.aspx

Something roughly like this:

// in html you have this
<script src="WebService.asmx/jsdebug" type="text/javascript"></script>

// csharp web-service like this
[WebMethod]
public int Add(int a, int b) { return a + b; } 


// further javascript to call it
function CallAdd()
{
    // method will return immediately
    // processing done asynchronously
    WebService.Add(0,6, OnMethodSucceeded, OnMethodFailed);
}

This should eliminate the need to post parameters via query-string, which is typically not supported in a soap environment, as the service expects a well-formed soap message.

Comments

0

Hi I'm using the jQuery jqGrid plugin and by default it posts 5 or 6 parameters to the url. I was having trouble getting to those parameters and from looking at some of the php examples, it showed the method grabbing the parameters from the Form variables...I was just trying to see if there was a way I could do that. I'll see what I can do about posting them as parameters. . . just for giggles, is there a way that I would or could do this though?

1 Comment

I use jqgrid. It doesn't post in the URL (as querystrings) -- it posts everything as POST parameters. So, in ASP.NET, you should be able to get, for example, the requested page number as Request.Form("page").
0

I'm having a similar problem.

I'm using jQuery/json and POSTing back to a C#/Webservice. I don't know how to read the json variable I created.

Here's the client side(on a user control):

<script type="text/javascript" language="javascript">
    function DoLogin() 
    {
        var un = document.getElementById('UserNameText').value;
        var pw = document.getElementById('PasswordText').value;
        var info = "{ 'UserName':'" + un + "', 'Password':'" + pw + "'}";

        $.ajax(
        {
            type: "POST",
            url: "http://localhost:60876/Sitefinity/Services/Login/Login.asmx/LoginSpecial",
            dataType: 'json',
            data: info,
            contentType: "application/json; charset=utf-8",
            success: function (msg) { alert(msg.d); },
            error: function (msg) { alert(msg.responseText); }
        });
    }
</script>

Here's the web service side:

    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
     [System.Web.Script.Services.ScriptService]
    public class Login : System.Web.Services.WebService
    {
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        [WebMethod]
        public string LoginSpecial()
        {
            // read the json variables: UserName, Password.

            string un = HttpContext.Current.Request["UserName"] != null ? HttpContext.Current.Request["UserName"].ToString() : String.Empty;
            // the previous isn't working for some reason.

            return "Some message here";
        }
    }

I'm getting to the webservice but I need the Username/Password from json to do some validation.

Comments

0

for ASP.NET....

you can get the POST parameters with Request["paramName"];

If your using a GET request with query string parameters then

Request.QueryString["paramName"];

Comments

0
string parameter = HttpUtility.ParseQueryString(HttpContext.Current.Request.UrlReferrer.Query).Get("param1");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.