<html>
<body>
<form runser="server">
<img src="a.jpg"/>
<intype type="text"/>
<input type="button" onclick="test()" value="提交">
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="GetPicture" Visible="false"/>
<script type="text/javascript">
function test()
{
document.getElementById("Button1").click();
}
</script>
</from>
<body>
</html>
<body>
<form runser="server">
<img src="a.jpg"/>
<intype type="text"/>
<input type="button" onclick="test()" value="提交">
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="GetPicture" Visible="false"/>
<script type="text/javascript">
function test()
{
document.getElementById("Button1").click();
}
</script>
</from>
<body>
</html>
1,利用xmlhttprequest来访问aspx页面
2,aspx页面Response图片的名称,比如是B.JPG
3,xmlhttp对象接收到这个responseText
4,JS替换掉img的src即可剩下的到网上找一下代码即可了
<head runat="server">
<title>无标题页</title>
<script language="javascript" type="text/javascript">
function getPic()
{
document.getElementById("aaa").src = '<%=GetPicture()%>';
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<img id="aaa" src="a.pic"/>
<input type="button" onclick="getPic()"/> </div>
</form>
</body>
</html>
<script>
var http_request ;function newRequest()
{
var rr = false;
if (window.XMLHttpRequest)
{
rr = new XMLHttpRequest();
if (rr.overrideMimeType)
{
rr.overrideMimeType('text/xml');
}
}
else if (window.ActiveXObject)
{
try {rr = new ActiveXObject("Msxml2.XMLHTTP");}
catch (e) { try {rr = new ActiveXObject("Microsoft.XMLHTTP"); }catch (e2) {}
}
}
else
{
alert("未知的浏览器,无法处理!");
}
return rr;
}function getPIC(url)
{
http_request = newRequest();
if(!http_request)
{
return false;
}
http_request.onreadystatechange = alertRemind;
http_request.open('GET',url,true);
http_request.send(null);
}function showPIC()
{
if(http_request.readyState == 4)
{
if (http_request.status == 200)
{
picID.innerHTML="<img src='"+http_request.responseText+"'>";
}
}
}</script>
在你的页面按钮的onclick事件中,加入:getPIC(url),url是你的服务器端获取图片的aspx文件,返回的结果是"a.jpg"这种格式.
同时,你的页面需要显示图片的位置,加个span或div都可以,定义为picID.
错了,改为http_request.onreadystatechange = showPIC;
<TBODY>
<TR><TD width="80"></TD>
<TD><B><FONT color="#0077b2"><span id="title">用户登录</span></font></B></TD>
</TR>
<TR>
<TD align="right" width="80"><B><FONT color="#0077b2">用户名:</FONT></B></TD>
<TD align="left"><INPUT class="SmallInput" maxLength="30" size="18" name="username"></TD>
</TR>
<TR>
<TD align="right" width="80"><B><FONT color="#0077b2">密 码:</FONT></B></TD>
<TD align="left"><INPUT class="SmallInput" maxLength="30" size="18" name="userpass" type=password></TD>
</TR>
</TBODY></TABLE>
<TABLE cellSpacing="8" cellPadding="0" width="365" border="0">
<TBODY>
<TR>
<TD align="left" height="32">
<img border=0 width="70" height="22" name="login" src="images/login_button_01.gif" onClick="callServer();" style="cursor:hand;">
<A href="index.html" target="_self"><IMG height="22" src="images/login_button_02.gif" width="70" border="0"></A>
</TD>
</TR>
</TBODY></TABLE>
<script language="javascript" type="text/javascript">
var xmlHttp = false;
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();
}function callServer() {
var username = document.getElementById("username").value;
var userpass = document.getElementById("userpass").value;
if ((username == null) || (username== "")) return;
var url = "Ajax.aspx?username=" + escape(username) + "&userpass="+escape(userpass);
xmlHttp.open("GET", url, true);
xmlHttp.onreadystatechange = updatePage;
xmlHttp.send(null);
}function updatePage() {
if (xmlHttp.readyState < 4) {
title.innerHTML="验证中...";
}
if (xmlHttp.readyState == 4) {
var response = xmlHttp.responseText;
if (response=='ok'){
top.location.href='DeskTop.htm';
}
else{
title.innerHTML=response;
}
}
}
</script>
Sub AjaxChk()
Dim myDB As New DealDB
Dim result As Integer = myDB.Userlogin(Request("username"), EncryptPassword(Request("userpass"), "SHA1"))
If result > 0 Then
Response.Cookies("myCookies")("myID") = result
Response.Write("ok")
Else
Response.Write("用户名或密码错误!")
End If
End Sub
{
var xmlHttpRequest = false;
//IEN???
if(window.ActiveXObject)
{
xmlHttpRequest = new ActiveXObject('Microsoft.XMLHTTP');
}
else
{
xmlHttpReq = new XMLHttpRequest();
xmlHttpReq.overrideMimeType('text/xml');
}
xmlHttpRequest.open('POST', actionUrl, false);
xmlHttpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlHttpRequest.onreadystatechange = function() {
if(xmlHttpRequest.readyState == 4)
{
switch (xmlHttpRequest.status)
{
case 404:
alert('ERROR: ' + actionUrl + ' NOT EXIST!');
break;
case 500:
alert('ERROR: ' + xmlHttpRequest.responseText);
break;
default:
eval(resultFunction + '(xmlHttpRequest.responseText);');
break;
}
}
}
xmlHttpRequest.send(submitParameter);
}