原来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
你上面是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>