json object sent with xmlhttprequest need to be saved on server. I see "200 ok" from Firebug. But I have 3 problems:
- server side scripting/.cs didn't run
- how can I save the data posted
- the response/responseText is the whole page .aspx , how can I change it?
Thank you. Please refer to the following code:
.aspx :
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="xhr1.aspx.cs" Inherits="ohmy" %>
javascript :
var jsonobject={"time":"10:00am","temparature":"55"};
var data=JSON.stringify(jsonobject);
var url = "xhr1.aspx/savetofile?timeStamp=" + new Date().getTime();
var req = new XMLHttpRequest();
req.onerror = function() {};
req.onreadystatechange = function() {if (req.readyState == 4) {}};
req.open('POST', url, false);
req.setRequestHeader("Content-Type", "application/json");
req.send(data);
.cs :
using System;
using System.IO;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class ohmy : System.Web.UI.Page
{
[System.Web.Services.WebMethod]
public static object savetofile(string data)
{ }
}
helper class is missing in program.