Trying to use this code
i reached a dead end, in the client side the form values collcected and serialized , but since it's not possible to use an instance of request in a static method i failed to receive the seialized form values at the server, i tried to bypass it by using the static HttpContext.Current.Request.InputStream but i got empty stream. how can i get the input stream in the server ? client side :
function myFunction() {
$.ajax({
type: "POST",
url: "ajaxForm.aspx/Receiver",
contentType: "application/json; charset=utf-8",
data: $('#myForm').serialize(),
datatype : "json",
cache: false,
success: function (data) {
$('#result').html(data);
},
error: function (data) {
alert('failed');
}
});
}
server side first version (copied from that link):
{
string json;
using(var reader = new StreamReader(Request.InputStream)){
json = reader.ReadToEnd();
}
second version :
[WebMethod ]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static void Receiver()
{
if (HttpContext.Current.Request.InputStream.Position != 0)
{
HttpContext.Current.Request.InputStream.Seek(0,System.IO.SeekOrigin.Begin);
}
byte[] data = new byte[HttpContext.Current.Request.InputStream.Length];
HttpContext.Current.Request.InputStream.Read(data, 0, data.Length);}