100分求教 sendReq无法通过webconfig将请求发送到后台?

hinada99 2011-03-04 05:33:39

1>sendTest.htm中代码:
//点击按钮触发
function Goto()
{
sendReq("Middle.cs?info=hello",null,Receive);
}

//发送函数
function sendReq(url, data, stateChange){
var xmlHttp;
try{
xmlHttp=new XMLHttpRequest();
}
catch (e){
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){
alert("您的浏览器不支持AJAX");
return;
}
}
}
xmlHttp.onreadystatechange = function(){
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200) {
stateChange(xmlHttp.responseText);
}
else{
alert("服务端异常");
}
}
}
xmlHttp.open("post",url,true);
xmlHttp.send(data);
}

//接收函数
function Receive()
{
alert("Back Arrived");
}

2>web config中代码
<httpHandlers>
<add verb="*" path="Middle.cs" type="TESTWSL.Middle,TESTWSL"/>
</httpHandlers>

3>TESTWSL类库
Middle.cs代码

using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using TESTBLL;

namespace TESTWSL
{
public class Middle:IHttpHandler
{
public bool IsReusable
{
// 如果无法为其他请求重用托管处理程序,则返回 false。
// 如果按请求保留某些状态信息,则通常这将为 true。
get { return true; }
}

public void ProcessRequest(HttpContext context)
{
//在此写入您的处理程序实现。
if (context.Request.QueryString["info"].ToString() == "hello")
{
context.Response.Write(TESTBLL.Back.SendInfo());
}
}

}
}

4>TESTBLL类库
Back.cs代码
using System;
using System.Collections.Generic;
using System.Text;

namespace TESTBLL
{
public static class Back
{
public static string SendInfo()
{
return "You have arrived at backStage";
}
}
}

//原帖在http://topic.csdn.net/u/20110304/17/3c3630be-75c2-48d2-b3d9-56f9bca711a0.html?seed=1364327431&r=71952558
//求高人指教
...全文
114 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Abafi 2011-03-08
  • 打赏
  • 举报
回复
http://topic.csdn.net/u/20110307/10/1af462ba-04fa-48b0-8da3-5c90345f2167.html
第72楼 我的标准答案,请楼主笑纳
hinada99 2011-03-07
  • 打赏
  • 举报
回复
//是不是webconfig里面除了
<httpHandlers>
<add verb="*" path="Middle.cs" type="TESTWSL.Middle,TESTWSL"/>
</httpHandlers>
这段外,还要加其他代码?
hinada99 2011-03-04
  • 打赏
  • 举报
回复
调试的 时候总是 无法 进行到 WSL中的Middle.cs中,

发送函数中,
if (xmlHttp.status == 200) {
stateChange(xmlHttp.responseText);
}
else{
alert("服务端异常");
}
这里报错,xmlHttp.status=404,"NotFound".
这个是因为webconfig的原因还是哪的原因。
求Ajax达人赐教, 使上述程序能够运行,或者提供一个 类似上面的 3层结构的 网站程序的达人,得100分~

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧