Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I post large data through an AJAX call (jQuery)?

Tags:

jquery

ajax

I am trying to use jQuery's ajax functionality to update data from a web form (ASP.NET MVC). Part of the data comes from a text area, and while is not a huge amount of data, can easily be more than 2 KB.

It seems that jQuery ajax puts all data into the query string, hence causing IIS to reject the URL, hence breaking the call. Is it possible to add data to a POST request using the ajax model under jQuery, rather than having everything in the query string?

like image 202
Darren Oster Avatar asked Jan 15 '09 02:01

Darren Oster


2 Answers

use $.post

e.g

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

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

$.ajax({ type :"post", 
         data : { textData: $('#someInput').val() },
         url : someUrl
      });
like image 95
redsquare Avatar answered Sep 22 '22 21:09

redsquare


Yes; according to jQuery's documentation, you can use jQuery.post to POST data.

If you want to post an existing form, use:

var form = $("#myform"); // or whatever
$.post(form.get()[0].action, form.serialize(), function(data) {
    // data received
}, "xml");
like image 38
strager Avatar answered Sep 24 '22 21:09

strager