1

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?

7
  • 1
    Better to use jQuery POST instead of GET. Commented Jul 2, 2014 at 7:46
  • 3
    Use $.post for larger data Commented Jul 2, 2014 at 7:46
  • Maybe I can write it to server side text file from JavaScript and then trough PHP open it and read it? And OK will try to use POST. Commented Jul 2, 2014 at 7:46
  • @veiss no, its not possible and even if it was, its just more complicated. use $.post as suggested and all should be fine Commented Jul 2, 2014 at 7:47
  • No, you cannot. Use POST! Commented Jul 2, 2014 at 7:47

1 Answer 1

3

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'];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.