krzyhub
krzyhub

Reputation: 6540

How can i send data via post request?

I have form which data will be sent via ajax. It is normal string-type content from textarea. But i don't know how can i tell jquery that i want sent this words as data.

$.ajax({
  type: 'POST',
  url: url,
  data: data,
  success: success,
  dataType: dataType
});

Could someone can give me any tips?

Upvotes: 0

Views: 121

Answers (4)

Gabriele Petrioli
Gabriele Petrioli

Reputation: 196306

You can use the .serialize() docs method

$.ajax({
  type: 'POST',
  url: url,
  data: $("#YourFormIdHere").serialize(),
  success: success,
  dataType: dataType
});

Upvotes: 1

shanethehat
shanethehat

Reputation: 15580

If your text area has an id:

<textarea id="myText"></textarea>

then you would send it like this:

$.ajax({
  type: 'POST',
  url: url,
  data: "data="+$('#myText').val(),
  success: success,
  dataType: dataType
});

Upvotes: 0

mgalgs
mgalgs

Reputation: 16809

data = $("#my-text-area").val()

or maybe I misunderstood your question...

Upvotes: 1

genesis
genesis

Reputation: 50982

var data = $("form").serialize();
$.ajax({
  type: 'POST',
  url: url,
  data: data,
  success: success,
  dataType: dataType
});

Upvotes: 5

Related Questions