Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #24339 > unrolled thread
| Started by | trudge <nospam@softouch.on.ca> |
|---|---|
| First post | 2014-05-22 06:18 -0400 |
| Last post | 2014-05-22 13:41 -0400 |
| Articles | 9 — 5 participants |
Back to article view | Back to comp.lang.javascript
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
| From | trudge <nospam@softouch.on.ca> |
|---|---|
| Date | 2014-05-22 06:18 -0400 |
| Subject | Pass variable from Perl-AJAX-Perl |
| Message-ID | <7akfv.180209$6A3.141820@fx29.iad> |
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. -- Amer Neely
[toc] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2014-05-22 12:20 +0100 |
| Message-ID | <0.cb8ce465599fb6e5a937.20140522122015BST.87lhturrf4.fsf@bsb.me.uk> |
| In reply to | #24339 |
trudge <nospam@softouch.on.ca> writes: > 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? Yes. You have a client-side script making an HTTP request. That script has access to the DOM (the internal representation of the document your user is looking at) which includes selection options, checkbox states and so on. The problem I have is understanding where the problem is. What have you got? What have you tried? Maybe the problem is the form that the request will take? The simplest option is to pass the data to the server in the query string of the requested URL. E.g. your script might request "http://myserver/info?isbn=42". -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | trudge <nospam@softouch.on.ca> |
|---|---|
| Date | 2014-05-22 12:25 -0400 |
| Message-ID | <Xxpfv.2613762$g45.648553@fx10.iad> |
| In reply to | #24340 |
On 14-05-22 7:20 AM, Ben Bacarisse wrote:
> trudge <nospam@softouch.on.ca> writes:
>
>> 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?
>
> Yes. You have a client-side script making an HTTP request. That script
> has access to the DOM (the internal representation of the document your
> user is looking at) which includes selection options, checkbox states
> and so on.
>
> The problem I have is understanding where the problem is. What have you
> got? What have you tried?
>
> Maybe the problem is the form that the request will take? The simplest
> option is to pass the data to the server in the query string of the
> requested URL. E.g. your script might request
> "http://myserver/info?isbn=42".
>
Hi Ben and thank you for the advice and apologies for the lack of
details. In my HTML page I call the first perl script:
ajaxRequest.open("POST", "http://127.0.0.1/cgi-bin/ajax/kba-search.pl",
true);
which populates my select lists. Then I need to capture the user choice
(say a book title) so I can pass it to another Perl script to return the
data about that choice.
How do I capture that data? In Perl or JavaScript? Once I have that then
I can take your suggestion and use it in a GET or POST.
--
Amer
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2014-05-22 19:16 +0200 |
| Message-ID | <280169017.qlGG4jz0K9@PointedEars.de> |
| In reply to | #24347 |
trudge wrote:
^^^^^^
Your real name should be there.
> In my HTML page I call the first perl script:
No, you do not.
> ajaxRequest.open("POST", "http://127.0.0.1/cgi-bin/ajax/kba-search.pl",
> true);
>
> which populates my select lists.
No, most certainly it does not. If you use the XMLHttpRequest API directly,
this only *prepares* to make an HTTP request to your locally installed Web
server – it is the send() call that makes it –, and the part of your code
that processes the resulting response populates the “select” elements
(likewise, in the function whose reference is assigned to the
“onreadystatechange” or “onload” property).
In a sufficiently modern runtime environment, it would go like this:
var ajaxRequest = new XMLHttpRequest();
ajaxRequest.open("POST", "http://127.0.0.1/cgi-bin/ajax/kba-search.pl",
true);
ajaxRequest.onload = function () {
/* populate the “select” elements */
};
ajaxRequest.send(null);
(A retrieval operation should be a *GET* operation instead. See REST.)
> Then I need to capture the user choice (say a book title) so I can pass it
> to another Perl script to return the data about that choice.
>
> How do I capture that data? In Perl or JavaScript?
Since Perl usally does not run in the Web browser, you would have to use an
ECMAScript implementation like JavaScript to access the DOM implementation
in order to determine the user selection.
Have you read the FAQ yet? If no, why not? Obviously you also have not
read the XHR tutorial I have referred you to.
--
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not Cc: me. / Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | John Harris <niam@jghnorth.org.uk.invalid> |
|---|---|
| Date | 2014-05-23 10:13 +0100 |
| Message-ID | <q54un9to07p84h7gpi5aso9eehvkfhh9af@4ax.com> |
| In reply to | #24349 |
On Thu, 22 May 2014 19:16:26 +0200, Thomas 'PointedEars' Lahn <PointedEars@web.de> wrote: >trudge wrote: >^^^^^^ >Your real name should be there. <snip> This is Usenet. Pen names are perfectly acceptable. Only the security organisations of paranoid states insist on knowing your "real" name. John
[toc] | [prev] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2014-05-22 17:30 +0000 |
| Message-ID | <lllc6u$nch$2@dont-email.me> |
| In reply to | #24347 |
On Thu, 22 May 2014 12:25:27 -0400, trudge wrote:
> On 14-05-22 7:20 AM, Ben Bacarisse wrote:
>> trudge <nospam@softouch.on.ca> writes:
>>
>>> 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?
>>
>> Yes. You have a client-side script making an HTTP request. That
>> script has access to the DOM (the internal representation of the
>> document your user is looking at) which includes selection options,
>> checkbox states and so on.
>>
>> The problem I have is understanding where the problem is. What have
>> you got? What have you tried?
>>
>> Maybe the problem is the form that the request will take? The simplest
>> option is to pass the data to the server in the query string of the
>> requested URL. E.g. your script might request
>> "http://myserver/info?isbn=42".
>>
>>
> Hi Ben and thank you for the advice and apologies for the lack of
> details. In my HTML page I call the first perl script:
>
> ajaxRequest.open("POST", "http://127.0.0.1/cgi-bin/ajax/kba-search.pl",
> true);
>
> which populates my select lists. Then I need to capture the user choice
> (say a book title) so I can pass it to another Perl script to return the
> data about that choice.
>
> How do I capture that data? In Perl or JavaScript? Once I have that then
> I can take your suggestion and use it in a GET or POST.
You capture anything that happens in the form in javascript. You then
have to encode it into an ajax request, either using the get or post
methods, which you then send to your perl script.
Your perl script will probably either use a library to extract the
request variables from the http request, or will need to parse the input
it receives from the web server. In either case, my knowledge of such
things is limited, and as (a) it's very easy to introduce security
vulnerabilities by parsing such input in an unsafe manner, (b) perl isn't
really on topic here, and (c) I haven't user perl for years; I'm not
going to suggest any solutions to you - I suggest you find a perl
newsgroup where they know about such things.
--
Denis McMahon, denismfmcmahon@gmail.com
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2014-05-22 13:27 +0200 |
| Message-ID | <2233284.cOHuCZCsUg@PointedEars.de> |
| In reply to | #24339 |
trudge wrote: ^^^^^^ This is Usenet. Please fix. > I start with an HTML page In most cases, there are no HTML pages. The concept of “pages” depends on a particular form of presentation; HTML does not (a fact often carelessly neglected by Web authors). > calling a Perl script to populate several select lists (title, author, > subject). You have server-side Perl generate an HTML document upon HTTP request, and the Web server to serve that document in an HTTP response to the client. > 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. Only in a very broad sense of “call”. You can make an HTTP request from the client that causes the Web server to execute Perl, Perl to generate content, the Web server to serve that content in an HTTP response, and you can process that response on the client. > Is this something that is even possible with AJAX? Needless to say AJAX > is new to me. AJAX (Asynchronous JavaScript And XML) is not a technology; it is a common misnomer for a *technique* (XMLHttpRequest – XHR) to make HTTP requests and handle the resulting HTTP responses when the main Web document has been loaded. Saying to “pass something back to AJAX” or “call AJAX” makes as little sense as “pass something back to backtracking” or “call the refactoring”, for example. (You need to call an object’s methods to make those HTTP requests, but that is something else.) Knowing this now, you can answer your question. > 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. HTTP does not care how you generate transmitted content and mostly also not what the content is; neither does XHR. This is one reason why "AJAX" is a misnomer, as XML is almost always not involved anymore (JSON is the preferred format). The proper term, XMLHttpRequest, is the name of the implemented interface (originally only Microsoft’s IXMLHttpRequest), and is only accepted because it gives that reference, and for lack of a better term. See below and STFW (avoid w3schools.com, probably even jquery.com at this point – and of course all football-related sites). -- PointedEars FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/> Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix> Please do not Cc: me. / Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2014-05-22 17:04 +0000 |
| Message-ID | <lllam8$nch$1@dont-email.me> |
| In reply to | #24339 |
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
[toc] | [prev] | [next] | [standalone]
| From | trudge <nospam@softouch.on.ca> |
|---|---|
| Date | 2014-05-22 13:41 -0400 |
| Message-ID | <PEqfv.379952$to2.170721@fx18.iad> |
| In reply to | #24348 |
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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web