我用的是post方法,然后接收到的参数都是空值这是为什么呢,原来还有值呢,现在却接收 不到了,
解决方案 »
- 急、急、急、关于在vs2005下使用WebDeployment Project插件发布网站的怪异问题
- 不显示删除回复显示所有回复显示星级回复显示得分回复 鼠标移动菜单IE8下没问题,IE6下不出来
- GridView1后台动态绑定的!我想移除多余的
- 三层架构中,我在IDAL里引用了一个Model.dll,引用后名字代命名空间
- UpdatePanel 触发Javascript脚本的问题
- 如何用jmail判断这封邮件客户已经被阅读?
- 我想用c#三层结构的oa换c#三层结构的全站程序学习。
- SDKEditor 1.0.7(可与VS.Net集成的HTML编辑器控件)源代码下载
- 求教:在DropDwonList中,如果某个item的数据太长,如何实现在此控件中只显示一部分,当鼠标放上去时,在鼠标附近出现显示全部数据的消息
- 求ASP.NET入门级教程电子书下载地址
- 文章发布系统分栏显示文章标题,用datareader和repeater哪种显示方法速度快?
- Repeater中用HTTM显示各天价格
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PostXML.aspx.cs" Inherits="ajax_xmlHttpRequest_PostXML" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<script type="text/javascript">
var xmlHttp=null;
function createXMLHttpRequest()
{
if(xmlHttp == null){
if(window.XMLHttpRequest) {
//Mozilla 浏览器
xmlHttp = new XMLHttpRequest();
}else if(window.ActiveXObject) {
// IE浏览器
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
}
}
}
}
}
function openAjax()
{
if( xmlHttp == null)
{
createXMLHttpRequest();
if( xmlHttp == null)
{
//alert('出错');
return ;
}
}
xmlHttp.onreadystatechange=xmlHttpChange;
xmlHttp.open("post","Result.aspx?date="+new Date().getTime(),true);
xmlHttp.send("<?xml version='1.0' encoding='utf-8'?><pet><type>cats</type><type>dogs</type></pet>"); }
function xmlHttpChange()
{
if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200)
{
document.getElementById('resultDiv').innerHTML=xmlHttp.responseText;
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<input type="button" value='post' onclick='openAjax();' />
<div id="resultDiv"></div>
</form>
</body>
</html>
protected void Page_Load(object sender, EventArgs e)
{
Response.Clear();
XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(Request.InputStream);
XmlNodeList selectedPetTypes = xmlDoc.GetElementsByTagName("type");
String type = null;
String responseText = "Selected Pets: ";
for (int i = 0; i < selectedPetTypes.Count; i++)
{
type = selectedPetTypes[i].FirstChild.Value;
responseText = responseText + " " + type;
}
Response.Write(responseText);
Response.End();
}
var html="";
var xmlHttp;
///获取url中的参数
function getUrlParameter()
{
var url=window.location.href;//获取当前的url
var index=url.indexOf("?");
var parameters;
if(index!=-1)
{
parameters=url.substr(index+1);
return parameters;
}
else
{
return "";
}
}
function getContent()
{
var controls=document.getElementById('temp').childNodes;
var html="";
for(var i=0;i<controls.length;i++)
{
html+=controls[i].innerHTML+"<br>";
}
return html;
}
//创建XMLHttpRequest对象
function createXmlHttpRequest()
{
if(window.ActiveXObject)//IE
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
{
xmlHttp=new ActiveXObject("MSXML2.XMLHTTP");
}
}
else if(window.XMLHttpRequest)//其它浏览器
{
try
{
xmlHttp=new XMLHttpRequest();
}
catch(e)
{
alert("您的浏览器不支持!")
}
}
}function UserOpear(method,url,divID)
{
createXmlHttpRequest();
url=url+"?date="+new Date().getTime();
var strSend="content="+getContent()+"&"+getUrlParameter()+"&now="+new Date().getTime();
xmlHttp.open("POST",url,true);
xmlHttp.onreadystatechange=getResult;
xmlHttp.send(strSend);
}
function getResult()
{
if(xmlHttp.readystate==4)
{
if(xmlHttp.status==200)
{
alert(xmlHttp.responseText);
}
}
}
<%@ WebHandler Language="C#" Class="GetTemp" %>
using System;
using System.Web;
public class GetTemp : IHttpHandler {
public void ProcessRequest (HttpContext context) {
//context.Response.ContentType = "text/plain";
string content = String.Empty ;
string actID = String.Empty;
content = context.Request.Params["content"];
actID = context.Request.Params["actID"];
WebSite.Model.UserInfo userModel = new WebSite.Model.UserInfo();
WebSite.BLL.UserInfoBll userBll = new WebSite.BLL.UserInfoBll();
userModel.userActID = Convert.ToInt32 (actID);
userModel.userInfo = content ;
if (userBll.Add(userModel) > 0)
{
context.Response.Write("操作成功!");
context.Response.Flush();
context.Response.End();
}
else
{
context.Response.Write("操作失败,稍后请重试!");
context.Response.Flush();
context.Response.End();
}
}
public bool IsReusable {
get {
return false;
}
}
}
content = context.Request.Params["content"];
actID = context.Request.Params["actID"];
content = context.Request.Form["content"];
actID = context.Request.Form["actID"];
send格式应该这样:send("name1=value1&name2=value2")。
因此试试:strSend="content="+getContent()+"&actID"++getUrlParameter()+"&now="+new Date().getTime()
后台里加上这个context.Response.ContentType = "application/x-www-form-urlencoded";
js中加上 xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
这样就OK了
function addPostParam(sParams, sParamName, sParamValue) {
if (sParams.length > 0) {
sParams += "&";
}
return sParams + encodeURIComponent(sParamName) + "="
+ encodeURIComponent(sParamValue);
}
context.Request.Form 并不是get 方式哦 ~ 是获得post 提交的参数context.Request.QueryString 才是获得get 方式 提交的参数哦~还有要注意的地方 就是function getUrlParameter()
{
var url=window.location.href;//获取当前的url
var index=url.indexOf("?");
var parameters;
if(index!=-1)
{
parameters=url.substr(index+1);
return parameters;
}
else
{
return "";
}
} var strSend="content="+getContent()+"&actID="+getUrlParameter()+"&now="+new Date().getTime();