急!ajax在本地运行良好,发布到IIS上就失效了,在线等
我是菜鸟,也没啥分谢谢各位大神,由衷感谢各位了,以下贴出代码,谢谢大家了
function CheckTeaMemPhoto()
{
var objFile=document.getElementById("fileTeaMemPhoto");
var filePath=objFile.value;
var index=filePath.lastIndexOf(".");
var fileType=filePath.substring(index+1,filePath.length);
if(!(fileType=="jpg"||fileType=="jpeg"||fileType=="png"||fileType=="bmp"||fileType=="gif"||fileType=="ico"))
{
document.getElementById("spanImgTeaMemPhoto").innerHTML="<img src=image/imgFalse.gif>";
document.getElementById("spanTeaMemPhoto").innerHTML="<p style=color:red;font-size:12px>图片格式不正确</p>";
}
else
{
CheckTeaMemPhotoSize();
}
}
var xmlHttp;
function createXMLHttpRequest()
{
if(window.ActiveXObject)
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
xmlHttp = new XMLHttpRequest();
}
}
function CheckTeaMemPhotoSize()
{
createXMLHttpRequest();
var url="CheckImgSize.ashx?filePath="+escape(document.getElementById("fileTeaMemPhoto").value);
alert(document.getElementById("fileTeaMemPhoto").value)
xmlHttp.open("Get",url,true);
xmlHttp.onreadystatechange=CheckTeaMemPhotoResult;
xmlHttp.send(null);
}
function CheckTeaMemPhotoResult()
{
alert("xmlHttp.readyState:"+xmlHttp.readyState)
if(xmlHttp.readyState==4)
{ alert("xmlHttp.status:"+xmlHttp.status)
if(xmlHttp.status==200)
{
if(xmlHttp.responseText=="bigger than max")
{
alert(xmlHttp.responseText);
document.getElementById("spanImgTeaMemPhoto").innerHTML="<img src=image/imgFalse.gif>";
document.getElementById("spanTeaMemPhoto").innerHTML="<p style=color:red;font-size:12px>图片超过500KB</p>";
}
if(xmlHttp.responseText=="photo not exist or damaged")
{
document.getElementById("spanImgTeaMemPhoto").innerHTML="<img src=image/imgFalse.gif>";
document.getElementById("spanTeaMemPhoto").innerHTML="<p style=color:red;font-size:12px>图片不存在或者不可用</p>";
}
if(xmlHttp.responseText=="ok")
{
ShowTeaMemPhoto();
document.getElementById("spanImgTeaMemPhoto").innerHTML="<img src=image/imgTrue.gif>";
document.getElementById("spanTeaMemPhoto").innerHTML="";
}
}
}
}
以下是处理页面CheckImgSize.ashx:
<%@ WebHandler Language="C#" Class="CheckImgSize" %>
using System;
using System.Web;
using System.IO;
public class CheckImgSize : IHttpHandler {
public void ProcessRequest (HttpContext context) {
string res = "";
context.Response.ContentType = "text/plain";
string filePath =context.Server.UrlDecode(context.Request.QueryString["filePath"].ToString());
FileInfo objFile = new FileInfo(filePath);
long size = Convert.ToInt64(System.Configuration.ConfigurationManager.AppSettings["ImgMaxSize"]);
if (objFile.Length < 0 || objFile.Length == 0)
{
res = "photo not exist or damaged";
}
else if (objFile.Length > size)
{
res = "bigger than max";
}
else if (objFile.Length > 0 && objFile.Length < size)
{
res = "ok";
}
context.Response.Write(res);
}
public bool IsReusable {
get {
return false;
}
}
}
在此谢谢大家了