Pierre
Pierre

Reputation: 13046

How to send long strings to a php file without a form?

I have a textarea inside a form (form action=post) and a link under this textarea, the user should fill this textarea and click the button to transfer the text written in the texarea to another file, I'm using jQuery to grab the textarea content and append them to the href of the link, this was working fine until I was testing the textarea with long strings.

so what is the alternative for sending very long strings to another php files ?

and thanks.

Upvotes: 1

Views: 1119

Answers (3)

Dr.Molle
Dr.Molle

Reputation: 117334

Use $.post , there is no size-limit for POST-data.

But when you want the behaviour of a link(opening the target-page), you'll need a form.

A simple approach:

<script  type="text/javascript">
/**
  * @param o mixed selector/element to send
  * @param a string url to send to
  * @param m optional string HTTP-method (default: 'post')
  * @param t optional string target-window(default: '_self')
  **/
function fx(o,a,m,t)
{
  $('<form/>')
    .attr({action:a,method:m||'post',target:t||'_self'})
      .css('display','none')
        .append($(o).clone())
          .appendTo('body')
            .submit()
              .remove();
}
</script>


<form>
 <input name="foo">
 <textarea id="textareaId" name="bar">foobar</textarea>
 <a style="cursor:pointer;text-decoration:underline" 
    onclick="fx('#textareaId','some.php')">send only the textarea</a>
</form>

It creates a new form on the fly, appends the desired element to the form and sends the form(to wherever you want to)

Upvotes: 5

swati
swati

Reputation: 1757

Use AJAX with POST method :

$.ajax({
  url: "test.php",
  context: document.body
}).done(function() { 
  alert("Success");
});

Upvotes: 1

Kris.Mitchell
Kris.Mitchell

Reputation: 998

There is a limit to the number of charachters you can send in a URL. IE url limit

That might have been your problem.

But you could use post in jquery as well

Upvotes: 0

Related Questions