首页 新闻 会员 周边 捐助

请大家帮忙看看这段关于XMLHTTP的asp代码在asp.net里该怎么改写?

0
[已解决问题] 解决于 2010-04-22 17:40

原来asp的程序现在要用.net重写,这段代码内容是 当 点击验证按钮,然后把一些信用卡信息发过去验证,然后并从返回的值里判断是否通过验证...

不过Server.CreateObject("MSXML2.ServerXMLHTTP")啥的我不太明白,不知道在.net里应该怎么写这里呢?还是应该写在js里?
我查了一下这个貌似跟现在的ajax有点关系?本来我想把这些写在按钮后台的触发事件里的,可是网上查了一下,这些貌似都是写在js里的....

我知道菜鸟不是借口,不过确实不懂不知该从哪下手,经理就这么扔给我让我自己想办法.... (┬_┬)
想请教一下各位大虾:

1. 这部分验证是写在哪里比较好?前台js还是后台?

2. 用c#/js大致该怎么改写呢?

或者指点一下我该查哪方面的资料.... 现在真的有点迷茫....

严重感谢!!!

--------------------------------------------------------------------------------

    strRequest = "type=auth"
        strRequest = strRequest & "&username=" & strPAUserName
        strRequest = strRequest & "&password=" & strPAPassword
        strRequest = strRequest & "&ccnumber=" & strPACreditCardNumber
        .......
        
         set xmlHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")
        xmlHTTP.Open "POST", strPAURL, False
        xmlHTTP.setRequestHeader "Content-Type","application/x-www-form-urlencoded"
        xmlHTTP.send strRequest
        strResponse = xmlHTTP.responseText
        set xmlHTTP = nothing
        
        aryPair = Split(strResponse, "&")
        
        set hstResponse = Server.CreateObject("Scripting.Dictionary")
        
        for each strPair in aryPair
            arySplitPair = Split(strPair, "=")
            hstResponse.Add arySplitPair(0), arySplitPair(1)
        next
        
        strResponseCode = hstResponse.Item("response_code")
        
        if hstResponse.Item("response") = "1" then
            strMessage = "SUCCESS: The credit card has been authorized.
        elseif hstResponse.Item("response") = "2" then
            strMessage = "DECLINED (" & strResponseCode & "): The credit card has declined.     
        end if
        
        if hstResponse.Item("response") = "1" then
            strTransactionID = hstResponse.Item("transactionid")
            strPreAuthStatus = hstResponse.Item("response")
        else
            strPreAuthStatus = "0"
        end if
        
        set hstResponse = nothing

问题补充: 重点是这部分,不知重写的话语法该是怎样的: set xmlHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP") xmlHTTP.Open "POST", strPAURL, False xmlHTTP.setRequestHeader "Content-Type","application/x-www-form-urlencoded" xmlHTTP.send strRequest strResponse = xmlHTTP.responseText set xmlHTTP = nothing
我爱阳光的主页 我爱阳光 | 菜鸟二级 | 园豆:204
提问于:2010-04-17 10:04
< >
分享
最佳答案
0

你上面是ASP VBScript吧,应该用到JS。我给你发给在ASP.NET中使用JS AJAX的例子。

registre.html
<head>
    <title>Register</title>
    <link href="StyleSheet.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">  
    var xmlHttp = false;   
    function checkUserName()
    {
        // 获取需要检查的用户名
        var tbUserName = document.getElementById('tbUserName');
        if (tbUserName.value == "")
            return;       
        //创建XMLHttpRequest对象
        try
        {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            try
            {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e2)
            {
                xmlHttp = false;
            }
        }
        if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
            xmlHttp = new XMLHttpRequest();
        }     
        
        // 构造需要提交的URL,并发送请求。请示成功回发callBack_CheckUserName函数。
        var url = "CheckUserNameService.aspx?UserName=" + tbUserName.value;
        xmlHttp.open("GET", url, true);
        xmlHttp.onreadystatechange = callBack_CheckUserName;
        xmlHttp.send(null);
    }
    
    function callBack_CheckUserName()
    {
        if (xmlHttp.readyState == 4)
        {
            var isValid = xmlHttp.responseText;
            var checkResult = document.getElementById("checkResult");
            checkResult.innerHTML = (isValid == "true") ? "" : "Please choose another name.";
        }
    }   
    </script>
</head>
<body>
    <table id="registerForm">
        <tr>
            <td class="title">
                User Name
            </td>
            <td>
                <input id="tbUserName" type="text" onblur="checkUserName()" />
                <span id="checkResult"></span>
            </td>
        </tr>
        <tr>
            <td class="title">
                Password
            </td>
            <td>
                <input id="tbPassword" type="password" />
            </td>
        </tr>
        <tr>
            <td rowspan="2">
                <input id="btnSubmit" type="submit" value="Submit" />
            </td>
        </tr>
    </table>
</body>

2.CheckUserNameService.aspx
<%@ Page Language="C#" %>
<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        string candidateUserName = Request["UserName"];       
        bool isValid = false;
        if (candidateUserName.ToLower() != "dflying")
        {
            isValid = true;
        }       
        Response.Clear();
        Response.Write(isValid ? "true" : "false");
        Response.Flush();       
    }
</script>

Astar | 高人七级 |园豆:40805 | 2010-04-17 10:45
谢谢,我研究一下~ 原来应该用ActiveXObject啊...
我爱阳光 | 园豆:204 (菜鸟二级) | 2010-04-17 11:08
还有有点迷糊,不过还是谢谢你 :)
我爱阳光 | 园豆:204 (菜鸟二级) | 2010-04-22 17:40
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册