Briana Finney Briana Finney - 11 months ago 77
ASP.NET (C#) Question

How to get URL Parameters from / jQuery.ajax POST?

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?

Answer Source

If you're using 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:

Something roughly like this:

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

// csharp web-service like this
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.