无刷新上传图片信息

<form id="formBug" name="formBug" method="post"
                  action="http://events.tiancity.com/cp/collect/api/collect_bug.php" enctype="multipart/form-data"
                  target="app_iframe" onsubmit="return validateForm(this);">
                <table width="470" border="0">
                    <tr>
                        <td width="138"><b>*</b> 操 作 系 统 :</td>
                        <td width="322"><input type="text" class="txt01" name="os" request="true" maxlength="40"/></td>
                    </tr>
                    <tr>
                        <td><b>*</b> 操作系统版本:</td>
                        <td><input type="text" class="txt01" name="os_version" request="true" maxlength="10"/></td>
                    </tr>
                    <tr>
                        <td colspan="2"><b>*</b> 摘 要(标题):</td>
                    </tr>
                    <tr>
                        <td colspan="2"><textarea id="textarea" name="title" class="textarea01"
                                                  request="true" maxlength="40"></textarea></td>
                    </tr>
                    <tr>
                        <td colspan="2"><b>*</b> 详 细 描 述 :</td>
                    </tr>
                    <tr>
                        <td colspan="2"><textarea id="textarea" name="description" class="textarea02"
                                                  request="true" maxlength="2000"></textarea></td>
                    </tr>
                    <tr>
                        <td colspan="2"><strong>上传文件(可选)(最大支持1024K)</strong>
                            <input type="file" class="up_img" value="浏览" size="15" name="file"/>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2"><b>* 为必填选项</b></td>
                    </tr>
                    <tr>
                        <td colspan="2"><input type="submit" value="" onfocus="this.blur()" class="btn01 input06"
                                               name="">
                        </td>
                    </tr>
                </table>
                <iframe id="app_iframe" name="app_iframe" width="0" height="0"
                        scrolling="no" frameborder="0"></iframe>
                <input type="hidden" name="submit_type" value="bug"/>
            </form>

原理是把form提交到iframe,然后iframe提交到服务器.

服务端处理完了以后可以使用JS调用客户端的回调函数

/* 返回消息 */
function showMessage ($msg)
{
    echo "<script>parent.callback('{$msg}')</script>";
    exit();
}
原文地址:https://www.cnblogs.com/bossikill/p/3103129.html