in reply to Is it possible to copy arrays from Javascript to Perl variable in the same Perl CGI script?

I can't tell if you are misunderstanding something fundamental or just wording your question poorly.

In either case, it's not clear to me exactly what you want to do.

The browser sends a request to the server, which runs your CGI script, which generates output including your javascript, which is then sent back to the browser, which is where your javascript is run.

Your javascript code can send that data back to your CGI script on a subsequent request, whether it be a form submission, embedded in a link that is clicked, or via ajax.

How you do it depends on what you want to do.

-sauoq
"My two cents aren't worth a dime.";
  • Comment on Re: Is it possible to copy arrays from Javascript to Perl variable in the same Perl CGI script?

Replies are listed 'Best First'.
Re^2: Is it possible to copy arrays from Javascript to Perl variable in the same Perl CGI script?
by lightoverhead (Pilgrim) on May 10, 2012 at 15:00 UTC

    Thank you sauq

    I know I can use ajax to transfer the array generated by js to a script

    However, could I transfer the array generated by js to the same Perl CGI script which generated the js script as well?

    As you noticed, that the array by js, "multipleVaule" will be copied to the "@array" in the same script.

    Should I just point the url in ajax (using CGI::Ajax as well) to the current one to carry out this task?

      However, could I transfer the array generated by js to the same Perl CGI script which generated the js script as well?

      Sure. But you'll have to code the script so that it knows what to do...

      I still have a nagging feeling that you are missing something fundamental though. You should think through the way data is moving between the browser and your script... remember, there is a new instance of the script running with each request from the browser.

      -sauoq
      "My two cents aren't worth a dime.";

        Frankly, what I would suggest that you do is to fire up, say, the Firebug debugger in Firefox and look at the HTTP transactions that take place between the client and the server.   You will see first-hand how the information is encoded and transferred.   If you then examine the documentation for, say, JQuery, alongside the corresponding documentation for CGI, you will then see how each side is equipped to deal with the transfer.

        The key point here is that there are two computer programs in play, written in two entirely different programming languages running on two computers, and they are exchanging data with one another using the agreed-upon protocol that is called "http."