Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: retrieving value from ajax call to cgi page

by moritz (Cardinal)
on Jun 29, 2013 at 11:22 UTC ( #1041449=note: print w/ replies, xml ) Need Help??


in reply to retrieving value from ajax call to cgi page

                  data : {'value1' ; value1},

This looks wrong. The correct way to write it would be {value1: value1}.

I highly recommend using firebug or chrome's developer tools (the one that opens when you press F12) when doing anything with javascript; otherwise the danger of running into javascript errors that are silently ignored is quite high.


Comment on Re: retrieving value from ajax call to cgi page
Select or Download Code
Re^2: retrieving value from ajax call to cgi page
by gayu_justin (Novice) on Jun 29, 2013 at 12:04 UTC

    On checking, i found that the page process.cgi is getting the value and since, this is an jax call, the value will not get print in the browser. please help me to take the value and all the text box value will be in the single variable

      Help me understand 'will not print in the browser.' Your JQuery snippet above just alerts the data, are you seeing the value in the alert box or not?

      If not, when you click on the network tab in firebug, look for your URL and ensure the response code was 200 (or whatever success code you're sending). If the ajax call http response was not successful, check your server error logs for any server side issues.

      If the ajax call was successful, click on the URL in firebug and click on the response tab. Is the data coming back the way you expect? If not, then check your server side logic to ensure you're doing what needs to be done (you can post your perl snippets then).

      If the data is coming back correctly, then double check the console tab in firebug -- you may have some other javascript error that's causing problems.

      -derby

      update: forgot to add, there's nothing special about AJAX for the perl/server side perspective. Wether the call is AJAX or the result of a click on an anchor element, perl/server side could care less. Many times when I'm debugging JQuery, I do the testing outside of the page on which the AJAX call resides. Wether that's a simple http://foo.com/cgi-bin/process.cgi?value=bar call on the browser or something more complicated via POSTing, it doesn't matter.

      try data : { value1: 'value1' },

      Here is my working test, an html page

      <html> <head> <script src="jquery-2.0.2.min.js"></script> <title>test-ajax.htm</title> <script> $.ajax({ url: 'process.cgi', // The type of request. type: "get", data : { value1: 'value1' }, success: function( data ){ alert(data); $( "#value1" ).html( "<strong>" + data + "</strong>" ); } }); </script> </head> <body> <span style="background-color:yellow" id="value1">?</span> </body> </html>
      and a process.cgi script.
      #!perl # process.cgi use strict; use CGI; my $q = CGI->new; print $q->header; print $q->start_html, 'Data returned is '.$q->param('value1'), $q->end_html;
      poj

        Okay, now from your browser-debugger add the actual GET/POST text, headers and all, that is being sent by your browser.   Also, notice how in the CGI example param() is being assigned to an @array ...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1041449]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2014-12-26 20:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls