469,275 Members | 1,871 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,275 developers. It's quick & easy.

AJAX Post Data? HttpContext.Current.Request doesn't seem to have the data.

I am brand new to .NET and I'm maintaining a website written in C# / .NET.

Basically, I'm modifying some AJAX to send a press release through POST instead of GET because of the size limitations associated with GET.

-------------------------------------------------

In the Javascript, I have:

Expand|Select|Wrap|Line Numbers
  1. var requestUrl    = ajaxengine_url + "?Action=SaveEvent"
  2. + "&artistid=" + GetSelectedOptions(document.getElementById("ManageEvent_ddlEventArtistName"));
  3.  
  4. var postVars = "pressrelease=" + encodeURIComponent(pressrelease);
  5.  
  6. CreateXMLHTTP();
  7. // If browser supports XMLHTTPRequest object
  8. if(XMLHTTP)
  9. {
  10.     XMLHTTP.onreadystatechange =  AuthenticateEvent;
  11.     XMLHTTP.open("POST", requestUrl,  true);
  12.     XMLHTTP.send(postVars);
  13. }
  14.  
----------------------

This seems to be working fine. I am able to retrieve the variables appended to the URL with no problem in C# using:
Expand|Select|Wrap|Line Numbers
  1. HttpContext.Current.Request["artistid"];
  2.  
I am able to retrieve and use the artistid information without a problem.

However,
Expand|Select|Wrap|Line Numbers
  1. HttpContext.Current.Request["pressrelease"]
  2.  
doesn't work.

Please give me some advice or a reference to read. I beating my head against a wall over here.

Thanks,

Lacy
May 9 '07 #1
2 9109
I am brand new to .NET and I'm maintaining a website written in C# / .NET.

Basically, I'm modifying some AJAX to send a press release through POST instead of GET because of the size limitations associated with GET.

-------------------------------------------------

In the Javascript, I have:

Expand|Select|Wrap|Line Numbers
  1. var requestUrl    = ajaxengine_url + "?Action=SaveEvent"
  2. + "&artistid=" + GetSelectedOptions(document.getElementById("ManageEvent_ddlEventArtistName"));
  3.  
  4. var postVars = "pressrelease=" + encodeURIComponent(pressrelease);
  5.  
  6. CreateXMLHTTP();
  7. // If browser supports XMLHTTPRequest object
  8. if(XMLHTTP)
  9. {
  10.     XMLHTTP.onreadystatechange =  AuthenticateEvent;
  11.     XMLHTTP.open("POST", requestUrl,  true);
  12.     XMLHTTP.send(postVars);
  13. }
  14.  
----------------------

This seems to be working fine. I am able to retrieve the variables appended to the URL with no problem in C# using:
Expand|Select|Wrap|Line Numbers
  1. HttpContext.Current.Request["artistid"];
  2.  
I am able to retrieve and use the artistid information without a problem.

However,
Expand|Select|Wrap|Line Numbers
  1. HttpContext.Current.Request["pressrelease"]
  2.  
doesn't work.

Please give me some advice or a reference to read. I beating my head against a wall over here.

Thanks,

Lacy
Lacy,

First thing I would do is see if Prototype Javascript Library would lower your code and ease some of your AJAX'n.

To answer your question you need to address the "Request" object.

Example: Request.Params["pressrelease"].ToString();

That will retrieve your parameter being posted.

I will strongly suggest using Prototype JS library or another framework so you can be cross-browser compliant and it is a heck of alot easier to code. If you need help with prototype email me and I can answer most questions about it for you.
Hope this helps

Bradd
May 10 '07 #2
Thank you for the help. I normally develop AJAX apps with Prototype. I'm not sure why the original developer didn't use it.

Also for future reference to anyone that might have a similar problem. I think I had two other problems in my code:

1 -- I don't think you can send info as GET and POST at the same time. One or the other. I was trying to do both.

2 -- If you send POST data the way I did, you have to set the content header:

Expand|Select|Wrap|Line Numbers
  1. XMLHTTP.open("POST", requestUrl,  true);
  2. XMLHTTP.setRequestHeader("Content-type", "application/x-www-form-urlencoded");            
  3. XMLHTTP.send(postVars);
  4.  
May 10 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by MarkMurphy | last post: by
3 posts views Thread by John Dalberg | last post: by
1 post views Thread by =?Utf-8?B?QnJhZCBLaW5n?= | last post: by
2 posts views Thread by =?Utf-8?B?Y2FzaGRlc2ttYWM=?= | last post: by
3 posts views Thread by Brett R. Wesoloski | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.