Search code examples
javascriptashxgeneric-handler

Sending large amount of data to ASHX handler


I need to send a pretty large amount of data from a web application to a ASHX handler. The handler will then send the data to a web service for a response. ( The reason the handler is dealing with the web service is because the web app is written in classic ASP and with the handler I am using .NET so I can just consume the service. )

What I need to do is send data to the handler with Javascript. Right now I am using an XMLHttpRequest and opening the correct URL. But I do not want to send a large amount of data through the query string. So my question is, how would I send a large amount of data to the handler? If there is another way besides using XMLHttpRequest, I am all ears.

Thanks


Solution

  • You can use a POST request instead of a GET request

    Generally data sent by get is appended to Query string ..

    Data sent by post is not appended to query string

    var url = "get_data.ashx";
    var params = "lorem=ipsum&name=binny";
    
    http.open("POST", url, true);
    
    http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http.setRequestHeader("Content-length", params.length);
    http.send(params);