How to send big data via an AJAX call (jQuery)?

I am trying to use jQuery ajax to update data from a web form (ASP.NET MVC). Some of the data comes from the text area, and although it is not a huge amount of data, it may be more than 2 KB.

It seems that jQuery ajax puts all the data in the query string, therefore, IIS rejects the url, hence breaking the call. Is it possible to add data to a POST request using the ajax model in jQuery and not have everything in the query string?

+5
source share
3 answers

use $. post

eg

$.post(someUrl, { textData: $('#someInput').val() } );

$. post is just a simple wrapper around $ .ajax.

$.ajax({ type :"post", 
         data : { textData: $('#someInput').val() },
         url : someUrl
      });
+8
source

; jQuery, jQuery.post POST.

, :

var form = $("#myform"); // or whatever
$.post(form.get()[0].action, form.serialize(), function(data) {
    // data received
}, "xml");
+6

FormData:

var formData = new FormData();
formData.append('filename', filename);
formData.append('data', data);
$.ajax({
    url: "FileUploadServlet",
    type: "POST",
    data: formData,
    cache: false,
    contentType: false,
    processData: false});
0
source

All Articles