0

I want to submit a form without loading a new php page. My form contains a file upload and textarea fields. Basically the data can like blog i.e large data size has to be submitted

I was going through some tutorial on jquery-ajax form submission

  • none of the tutorial show how to upload a file. can anyone help me with this and
  • since get method is used, is there a limitation on the size of data that can be submitted with jquery-ajax. If yes how should i handle it?
Stacy J
  • 2,721
  • 15
  • 58
  • 92

2 Answers2

2

You can use an iframe so you don't have to refresh the current page.

Many people go straight to plugins. But you can do this yourself pretty easily, and with all the functionality of an AJAX request.

Make a form submit to a hidden iframe that has a load event handler attached to it so when the form is submitted, you have a callback function that actually includes the server response (the HTML of the iframe after it loads).

Example:

<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>

and the Javascript code is:

(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
    });
});
Amith Koujalgi
  • 10,746
  • 2
  • 18
  • 22
0

As you know, limits are set not browsers. And according to many well-known directives, for example in Apache This paragraph defines the parameter LimitRequestBody. This parameter can take values ​​from 0 bytes to 2 GB. In PHP, there is also a directive called post_max_size. Specifies the size of a POST request.

Winston
  • 1,758
  • 2
  • 17
  • 29