是否有jquery-ajax表单提交的大小限制

时间:2013-02-23 09:09:38

标签: php jquery ajax file-upload size

我想在不加载新的php页面的情况下提交表单。我的表单包含文件上传和textarea字段。基本上数据可以像博客一样,即必须提交大数据量

我正在阅读关于jquery-ajax表单提交的一些教程

  • 没有教程展示如何上传文件。任何人都可以帮助我这个和
  • 由于使用了get方法,因此可以使用jquery-ajax提交的数据大小有限制。如果是,我应该如何处理它?<​​/ li>

2 个答案:

答案 0 :(得分:2)

您可以使用iframe,因此您无需刷新当前页面。

许多人直接插上插件。但是你可以很容易地自己完成这项工作,并具备AJAX请求的所有功能。

将表单提交给隐藏的iframe,该iframe附加了一个load事件处理程序,因此在提交表单时,您有一个回调函数,它实际上包含服务器响应(加载后iframe的HTML)。 / p>

示例:

<form action="..." method="post" encrypt="application/x-www-form-urlencoded" target="workFrame" >
    <input type="file" name="file" />
    <input type="submit" />
</form>
<iframe id="workFrame" src="about:blank" style="display:none;"></iframe>

和Javascript代码是:

(function () {
    $('form').on('submit', function () {
        //check if the form submission is valid, if so just let it submit
        //otherwise you could call `return false;` to stop the submission
    });

    $('#workFrame').on('load', function () {

        //get the response from the server
        var response = $(this).contents().find('body').html();

        //you can now access the server response in the `response` variable
        //this is the same as the success callback for a jQuery AJAX request
    });
});

答案 1 :(得分:0)

如您所知,限制不是设置浏览器。 并且根据许多众所周知的指令,例如在Apache中这一段定义了参数LimitRequestBody。此参数可以采用0字节到2 GB的值。在PHP中,还有一个名为post_max_size的指令。指定POST请求的大小。

相关问题