c#: with a Handler(.ashx) get post send with javascript
11,710
When you make a POST request, the value is not sent as part of the query string. So don't look in the query string for it. Retrieve it like this:
string ImeTvrtke = context.Request["CompanyName"];
Alternatively if you wanted to be sent as part of the query string then use a GET request:
jQuery.get('/CartHandler.ashx', { 'CompanyName': CompanyName });
Author by
Admin
Updated on June 04, 2022Comments
-
Admin almost 2 years
I am trying to get a string from a textbox in a .aspx page. When I debug my site jQuery.post is able to see the input value, but when I try to get the value in my handler, he is giving me NULL back. Anyone help!!!
JS:
CompanyName = $("#company").val(); jQuery.post('/CartHandler.ashx', { 'CompanyName': CompanyName });
ASHX:
public void ProcessRequest(HttpContext context) { string ImeTvrtke = context.Request.QueryString["CompanyName"]; }
-
Admin over 10 yearsI tryed with GET, it's the same.
-
Darin Dimitrov over 10 yearsHmm that's strange. Can you see the AJAX request being made in Fiddler?
-
Admin over 10 yearsWhen I post with jquery serialize, I am able to get in the handler the whole form, but I need only one string
-
Darin Dimitrov over 10 yearsThis should work with only a single value. Maybe the code you have shown in your question is not the actual code.
-
dougajmcdonald over 10 yearsIf you can't get the string, then your probably want the .Value of the Request[] / Request.Form[], apologies, I didn't understand that as your problem