要实现一表单,里头有一项是图片,需要无刷新上传,上传OK后提交表单。
图片存储的server和表单在不同域:
参考了
http://www.baidufe.com/item/8e4c451323dc5906927a.html
表单页 file:///E:/1.html:
<html>
<head>
<meta http-equiv=Content-Type content="text/html;charset=utf-8">
<script src="jquery-1.11.0.min.js"></script>
<script src="jquery-migrate-1.2.1.min.js"></script>
<script>
function uploadImg()
{
var names=$("#AidImg").val().split(".");
if(names[1]!="gif"&&names[1]!="GIF"&&names[1]!="jpg"&&names[1]!="JPG"&&names[1]!="png"&&names[1]!="PNG")
{
$("#imgError").html("<div class='bzsj_left'></div>"+"海报必须为gif,jpg,png格式");
$("#imgError").show();
return;
}
$("#formImg").submit();
}
function callback(message)
{
alert(message);
}
</script>
</head>
<body>
<form id="formImg" action="http://127.0.0.1:8081/upload" method="post" target="hidden_frame" enctype="multipart/form-data">
<div class="fromtrs">
<label>*活动海报:</label>
<input id="AidImg" class="sstp" type="file" name="AidImg" onchange="uploadImg()"/>
<div class="sjjt" style="display:none;" id="imgError">
<div class="bzsj_left"></div>活动海报不可为空</div>
</div>
</form>
<iframe style="display:none" name='hidden_frame' id="hidden_frame"></iframe>
<div class="fromtrs">
<img id="img" src="" width="80" height="80"/>
</div>
</body>
</html>
http://127.0.0.1:8081/upload 页输出
<iframe src="file:///E:/proxy?f=0.jpg" frameborder="0"></iframe>
file:///E:/proxy:
<script type="text/javascript">
var s = (location.hash || location.search).substr(1).split('&');
//top.callback(s[1]);
alert(s[0]);
</script>
我用chrome、ie为啥 alert不了 f=0.jpg。。。
在chrome看了,发现个奇怪的事,post之后内容好像是string啊???
<pre style="word-wrap: break-word; white-space: pre-wrap;"><iframe src="file:///E:/proxy?f=0.jpg" frameborder="0"></iframe>
</pre>
求教我怎么才能把上传后的文件alert出来。。。
我去,一直没招着前端,再这样下去我就疯了。。。
--
FROM 61.135.172.*