Reputation: 79
So I need to pass long string variable from JavaScript to PHP, but the URL shows me that its too long. I use this method:
function Fillup(id){
var answer = $('.nicEdit-main').html();
$.get('submit.php?id='+id+'&answer='+answer,
function(data){
$('.answer-div').html(data);
});
};
And grab them at the PHP file:
$id = $_GET['id'];
$answer = $_GET['answer'];
But there are times that answer
variable are long html codes. For example I created textarea with text editor options, witch you can see is .nicEdit-main
and if there is picture added, then my variable is too long to be passed trough URL. Can someone please suggest me a better method?
Upvotes: 1
Views: 1302
Reputation: 3986
You can try this:
function Fillup(id){
var answer = $('.nicEdit-main').html();
$.post('submit.php',
{
id: id,
answer: answer
},
function(data) {
$('.answer-div').html(data);
}
});
};
And in PHP side :
$id = $_POST['id'];
$answer = $_POST['answer'];
Upvotes: 3