Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #24348

Re: Pass variable from Perl-AJAX-Perl

From Denis McMahon <denismfmcmahon@gmail.com>
Newsgroups comp.lang.javascript
Subject Re: Pass variable from Perl-AJAX-Perl
Date 2014-05-22 17:04 +0000
Organization A noiseless patient Spider
Message-ID <lllam8$nch$1@dont-email.me> (permalink)
References <7akfv.180209$6A3.141820@fx29.iad>

Show all headers | View raw


On Thu, 22 May 2014 06:18:43 -0400, trudge wrote:

> I'm stuck on a problem I'm having with a project. I have a library built
> on a MySQL db and am trying to access it via AJAX & Perl.
> 
> I start with an HTML page calling a Perl script to populate several
> select lists (title, author, subject). User then picks an option (say
> book title) which then needs to call another Perl script to provide
> details of that choice.
> 
> I am stuck trying to pass a variable (say the option choice) back to
> AJAX so that I can use it to call the next Perl script.
> 
> Is this something that is even possible with AJAX? Needless to say AJAX
> is new to me.
> 
> I have an existing library running strictly on Perl
> [http://www.softouch.on.ca/kb/kb.html] and thought I would try it using
> AJAX.

It sounds to me as if you may have a fundamental lack of understanding of 
how the system goes together.

AJAX requests are requests that the javascript code running inside a web 
page in a web browser on the client computer make across the network 
using the http protocol to URLs that are typically processed by scripts 
running in a web server process on the server computer, and the output of 
those scripts then gets sent back by the web server as the response to 
the AJAX request, it is then received by the javascript engine in the web 
browser and made available to the javascript code.

So your user interacts with the web page in some way, this causes the web 
page to make an AJAX request to a url, in your case this url is 
presumably a perl script running on a web server, which then generates 
some response text (it's almost always text even when it's json or xml) 
which it sends back to the client, which then uses the text to somehow 
update the webpage for the user.

The most common ways of passing data from server side scripts to 
javascript in response to AJAX requests are probably JSON and XML data 
structures. These are methods of encoding data in text strings. JSON is 
probably more efficient than XML.

Yes it is possible to pass data back from the server side script in 
response to the AJAX request, but you can only send a single response 
back per request, and there are some constraints on the format of the 
response. Specifically, if you choose to use JSON data, then all the data 
that you send back in the JSON string becomes a single object in the 
javascript program. If you want to pass back several different data 
values in a single response you would typically first of all create a perl 
hash that contained all the data you wanted to send back, and then use 
the perl JSON stringify function to convert this to a JSON string. This 
string would become the response of the request, and the javascript would 
convert it into an object whose components you could access. You might 
also need to make sure that the response headers were appropriate for JSON 
data.

As it's a long time since I used perl I can't be much more help than 
this, sorry.

-- 
Denis McMahon, denismfmcmahon@gmail.com

Back to comp.lang.javascript | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Pass variable from Perl-AJAX-Perl trudge <nospam@softouch.on.ca> - 2014-05-22 06:18 -0400
  Re: Pass variable from Perl-AJAX-Perl Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-05-22 12:20 +0100
    Re: Pass variable from Perl-AJAX-Perl trudge <nospam@softouch.on.ca> - 2014-05-22 12:25 -0400
      Re: Pass variable from Perl-AJAX-Perl Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-05-22 19:16 +0200
        Re: Pass variable from Perl-AJAX-Perl John Harris <niam@jghnorth.org.uk.invalid> - 2014-05-23 10:13 +0100
      Re: Pass variable from Perl-AJAX-Perl Denis McMahon <denismfmcmahon@gmail.com> - 2014-05-22 17:30 +0000
  Re: Pass variable from Perl-AJAX-Perl Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-05-22 13:27 +0200
  Re: Pass variable from Perl-AJAX-Perl Denis McMahon <denismfmcmahon@gmail.com> - 2014-05-22 17:04 +0000
    Re: Pass variable from Perl-AJAX-Perl trudge <nospam@softouch.on.ca> - 2014-05-22 13:41 -0400

csiph-web