views:

42

answers:

2

Hi All, I have a situation where I have to send a large text in ajax request using method :POST. I have tried to do like this.

 new Ajax.Request(url + "?" + params, {
                method: 'post',postBody: {'Test':'Test'}, onSuccess: function (transport) {
                    switch (transport.responseJSON.Status) {
                        case "Success":
                            // alert(transport.responseJSON.Message);
                            var imgDiv = document.getElementById(control);
                            imgDiv.style.display = 'none';
                            break;
                        case "Failed":
                            alert(transport.responseJSON.Message);
                            break;
                        case "NotAuthorized":
                            alert(transport.responseJSON.Message);
                            break;
                        case "LoginRequired":
                            window.location = transport.responseJSON.RedirectAfterLogin;
                            break;

                    }

                }
            });   

Test in post body will be replaced with large text from a text area. But when I try to access it on server like this

string test = context.Request["Test"]; 

I get null. Any solution reference to an example? Thanks

+1  A: 

postBody is expected to be a name/value pair like this:

postbody:'Test=Test'

You would also need to add evalJSON = true if you want to use responseJSON assuming your returned content type is actually JSON

seengee
+1  A: 

Write

postbody:'Test=Test'

instead of

postbody: {'Test':'Test'}

As your text is large, so use escape() function so that it is transmitted to server safely. Also be sure that your query string and post body params not clash with each other.

Adeel