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

Re: perl dancer route template hashref pass complex json file to server issue

by Anonymous Monk
on Jul 25, 2016 at 22:38 UTC ( #1168514=note: print w/replies, xml ) Need Help??


in reply to perl dancer route template hashref pass complex json file to server issue

Hi,

Which version of Dancer?

Can you prove it? Can you post a short code example which demonstrates this bug?

  • Comment on Re: perl dancer route template hashref pass complex json file to server issue

Replies are listed 'Best First'.
Re^2: perl dancer route template hashref pass complex json file to server issue
by Anonymous Monk on Jul 25, 2016 at 23:18 UTC
    I don't see the claimed problem, it all works as it should
    >> Dancer 1.3202 server 2120 listenin >> Dancer::Plugin::EscapeHTML (0.22) http://localhost:3000/?jj={%22name%22:%22jsonFileexample%22,%22problem +%22:%22thisIsThrProblem\%22withComma%22};oj=jjjj
    {
      jj => "{\"name\":\"jsonFileexample\",\"problem\":\"thisIsThrProblem\\\"withComma\"}",
      oj => "jjjj",
    }

    use Dancer; use Data::Dump qw/ pp /; use Dancer::Plugin::EscapeHTML; any '/' => sub { "<pre>".escape_html( pp( scalar params() ) )."</pre>";;;; }; dance;
Re^2: perl dancer route template hashref pass complex json file to server issue
by RamiD (Acolyte) on Jul 26, 2016 at 05:36 UTC
    Hi , I will explain more with code example in my perl dancer code I have route
    use Dancer ':syntax'; our $VERSION = '0.1'; get '/PopUp' => sub { my $jsonFile={jj =>"{"name":"jsonFileexample","problem":"thisIsThrProb +lem\"withComma"}"} template 'PopUp' ,{'sendfileToserver'=>$jsonFile}; };
    in the server side I have the route that receive the perl dancer paramemters
    <script> var customjsonList ="<%customCommands%>"; alert(customjsonList.children.length) var output=customjsonList .split(","); alert(output) </script>
    so here in javascript I had the error , that some thing is wrong with the json file when I look at the error I saw that json file is missing the \
    {"name":"jsonFileexample","problem":"thisIsThrProblem"withComma"}" }
    I have perl dancer "Dancer 1.3202" thanks Rami D.

      Hi , I will explain more with code example in my perl dancer code I have route ... $jsonFile ...

      Sorry, that doesn't compile , its not perl

      $ perl nope Bareword found where operator expected at nope line 5, near ""{"name" (Missing operator before name?) String found where operator expected at nope line 5, near "name":"" Bareword found where operator expected at nope line 5, near "":"jsonFi +leexample" (Missing operator before jsonFileexample?) String found where operator expected at nope line 5, near "jsonFileexa +mple","" Bareword found where operator expected at nope line 5, near "","proble +m" (Missing operator before problem?) String found where operator expected at nope line 5, near "problem":"" Bareword found where operator expected at nope line 5, near "":"thisIs +ThrProblem" (Missing operator before thisIsThrProblem?) Backslash found where operator expected at nope line 5, near "thisIsTh +rProblem\" String found where operator expected at nope line 5, at end of line (Missing semicolon on previous line?) syntax error at nope line 5, near ""{"name" Can't find string terminator '"' anywhere before EOF at nope line 5.

      in the server side I have the route that receive the perl dancer paramemters

      That doesn't mention sendfileToserver

      so here in javascript I had the error , that some thing is wrong with the json file when I look at the error I saw that json file is missing the \

      So far you're not showing a problem with Dancer

      Most likely a problem in your template

      Use a JSON library to generate JSON values (we almost always use JSON::XS). Generating a JSON value by hand is error prone, especially when you don't know how escape characters work in quotes in the language you are writing in.

      #!/usr/bin/perl -l print qq<{"name":"jsonFileexample","problem":"thisIsThrProblem\"withCo +mma"}>;

      for example, produces:

      {"name":"jsonFileexample","problem":"thisIsThrProblem"withComma"}

      - tye        

        this is the code ( this time I've tried it :-) ) in my myapp.pm I had
        package myapp; use Dancer ':syntax'; use File::Slurp qw(read_file write_file read_dir); #use db; use JSON; use Data::Dump qw/ pp /; use DBI; our $VERSION = '0.1'; use Dancer::Plugin::Database; get '/test' => sub { my $jsonobj; $jsonobj='[{"name":"test","problem":"here is the problem \" comma +"}]'; debug $jsonobj; template 'test',{passtoserver=> $jsonobj}; };
        under the views I had file test.tt
        <!DOCTYPE html> <html> <head> </head> <body> <div style = "padding: 100px 100px 10px;"> <script> alert('<%passtoserver%>'); var test='<%passtoserver%>'; alert(JSON.stringify(test)); alert(JSON.parse(test)); </script> <button type="text" > </div> </body> </html>
        I had an error with JSON.parse(test) , when I had browser navigated to http://localhost:3000/test yes your right , when we do that with perl module rather than done by hand is a plus , but teh json file was generated by my website user and I'm just store it in DB , all the work on it just post and get from client and server thanks Rami D.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2023-02-05 20:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (32 votes). Check out past polls.

    Notices?