views:

149

answers:

3

I have a review PAGE with a TEXTFIELD. User need to be able to write LONG STORY (1000 words+) may contain chars like ()*&^%$#@\/<>

Once "save" is pressed I want to use Jquery GET -> to process content with PHP file. (save in mysql database)

and return result.

let's say I want to display "alert(words_were_saved:int)"

How can I pass through long, complex parameters to and from Jquery _POST, _GET without causing JS / HTTP errors ?

+1  A: 

You should use post for big data amounts. It works the same way:

jQuery.post( url, [data], [callback], [type] )

Load a remote page using an HTTP POST request. This is an easy way to send a simple POST request to a server without having to use the more complex $.ajax function. It allows a single callback function to be specified that will be executed when the request is complete (and only if the response has a successful response code).

The returned data format can be specified by the fourth parameter. If you need to have both error and success callbacks, you may want to use $.ajax. $.post is a (simplified) wrapper function for $.ajax. $.post() returns the XMLHttpRequest that it creates. In most cases you won't need that object to manipulate directly, but it is available if you need to abort the request manually.

Ghommey
+3  A: 

Try these:

using get:

var text = $('#textfield').val();
$.get('someurl.php",{data: text},function(result){
    alert(result);
}

Or using post(this should better than get when large data is submitted):

var text = $('#textfield').val();
$.post('someurl.php",{data: text},function(result){
    alert(result);
}

someurl.php:

$data = $_REQUEST['data'];
//do what you want to the data
//print some thing
echo 'saved';//this text will be alerted on get callback
jerjer
A: 

its best practice to use post for information that will change state (ie save, updated delete) and get just for serving content (text, html etc). this practice seems to keep matters nice and seperated and concise, and you can post large amounts of data.

Aliixx