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


Groups > comp.lang.javascript > #24351

Re: Pass variable from Perl-AJAX-Perl

From trudge <nospam@softouch.on.ca>
Newsgroups comp.lang.javascript
Subject Re: Pass variable from Perl-AJAX-Perl
References <7akfv.180209$6A3.141820@fx29.iad> <lllam8$nch$1@dont-email.me>
Message-ID <PEqfv.379952$to2.170721@fx18.iad> (permalink)
Date 2014-05-22 13:41 -0400

Show all headers | View raw


On 14-05-22 1:04 PM, Denis McMahon wrote:
> 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,

Thank you so much for a detailed and sensible reply. Yes you are right -
this is my first jump into AJAX and how it fits into everything. Thought
this would be a good exercise for me. hah.

I think you have shed some light on my particular situation with the
mention passing data via JSON or XML. I will have to dive deeper into this.

-- 
Amer

Back to comp.lang.javascript | Previous | NextPrevious 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