用xmlhttprequest发送的json对象需要保存在服务器上。我看到Firebug的“200 OK”。但是,我有3个问题:调试XMLHttpRequest POST
- 服务器端脚本/的.cs没跑
- 我怎么能救发布
- 响应数据/ responseText的是整个页面的.aspx,我如何改变它?
谢谢。请参考下面的代码:
的.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)
{ }
}
辅助类程序缺失。
是否有帮助:http://stackoverflow.com/questions/564289/read-post-data-submitted-to-asp-net-form – zmilojko