Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

javascript - Call Perl function in HTML using AJAX -


im having setback, im making html page javascript, , im using ajax call perl functions. thing when perl program doesn't need parameters calling trivial. have function open , read file need give location of file perl script, having passe trough paramenter in ajax calling. ex working call:

function getoption(){    var selectmenu=document.getelementbyid("select1")     selectmenu.onchange=function(){  //run code when "onchange" event fires     var chosenoption=this.options[this.selectedindex] //this refers "selectmenu"     if (chosenoption.value!="nothing"){      var s = chosenoption.text;      openfile("c:\perltest\test.txt");     }     }   } 

ex. not working trying pass parameter:

function openfile(name){  xmlhttp.open("get", "/cgi-bin/readfile.pl"+name, true);  xmlhttp.onreadystatechange = function() {  if (xmlhttp.readystate == 4) {     document.getelementbyid("txtarea").innerhtml = xmlhttp.responsetext;      }      }      xmlhttp.send(null);    } 

im attempting pass paremeter in way because of example:

http://www.suite101.com/content/how-to-create-a-simple-perl-ajax-application-a136201

can help??

thanks lot.


after sugestion of kinopiko, makes sense, have following:

html-

function openfile(name){             xmlhttp.open("get", "/cgi-bin/readfile.pl?file="+encodeuri(name), true);             xmlhttp.onreadystatechange = function() {             if (xmlhttp.readystate == 4) {                 var container = xmlhttp.responsetext.split("\n");                 if (container.length>0){                     ( i=0; i< container.length-1;i++){                         document.getelementbyid("txtarea").innerhtml += container[i] + " ";                     }                 }             }             else{                 document.getelementbyid("txtarea").innerhtml = "333";//xmlhttp.responsetext;             }             }             xmlhttp.send(null);         } 

perl script:

#!c:/perl/bin/perl  use strict; use cgi qw/param/;   use uri::escape;   print "content-type: text/html\n\n";  $file = param ('file');  $file = uri_unescape ($file);   open (myfile, $file);      while (<myfile>) {         chomp;         print "$_\n"; } close (myfile);  

now dont error in javascript, xmlhttp.readystate never 4, dont content of file.

maybe im using encodeuri wrong??

thanks.

first of need add question mark:

xmlhttp.open("get", "/cgi-bin/readfile.pl?file="+name, true); 

also need percent-encode "name" using encodeuri.

on perl end, can use module cgi value of file:

 use cgi qw/param/;  $file = param ('file'); 

then

 use uri::escape;  $file = uri_unescape ($file); 

Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -