Re: [Cppcms-users] Instantiate JsonRPC with dynamic URL path
Brought to you by:
artyom-beilis
|
From: CN <cn...@fa...> - 2014-07-22 10:17:57
|
Yes, your magic JsonRPC is loaded. Thanks a lot!
My script begin to work after rpc.get.on_result and
rpc.get.on_error are moved "inside" function init(). So, my
question can be ignored now.
Javascript to me is a language difficult to get it right :-)
--incorrect version starts--
function init(url){
rpc=new JsonRPC(url,['get'],[]);}
}
rpc.get.on_result=function(r){ alert(r); }
rpc.get.on_error=function(e){ alert(e); }
--incorrect version ends--
<html>
<head>
<title>My Title</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="json2.js"></script>
<script type="text/javascript" src="jsonrpc.js"></script>
<script type="text/javascript" src="myscript.js"></script>
</head>
<body>
<script type="text/javascript">
$(document).ready(function(){
init('<%= url %>');
rpc.get();
});
</script>
</body>
</html>
--correct version starts--
function init(url){
rpc=new JsonRPC(url,['get'],[]);}
rpc.get.on_result=function(r){ alert(r); }
rpc.get.on_error=function(e){ alert(e); }
}
Regards,
CN
On Tue, Jul 22, 2014, at 03:53 PM, Artyom Beilis wrote:
Show the full HTML...
Have you loaded the JsonRPC script from the contrib section -
the script that actually defines the JsonRPC object?
Artyom Beilis
--------------
CppCMS - C++ Web Framework: http://cppcms.com/
CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/
__________________________________________________________
From: CN <cn...@fa...>
To: cpp...@li...
Sent: Tuesday, July 22, 2014 8:50 AM
Subject: Re: [Cppcms-users] Instantiate JsonRPC with dynamic
URL path
I am trying to answer my own question. This variation seems to
be working:
html:
<body onload="init('<%= url %>');rpc.get()">
myscript.js:
function init(url){
rpc=new JsonRPC(url,['get'],[]);}
rpc.get.on_result=function(r){ alert(r); }
rpc.get.on_error=function(e){ alert(e); }
}
To me, javascript is a new world yet to be explored.
Regards,
CN
On Tue, Jul 22, 2014, at 11:24 AM, Lee Elenbaas wrote:
You can still place static files at other urls (even other
domain) and have the html refer to them and use them.
If you absolutely need the js url to change you can serve
static files from cppcms app
בתאריך 21 ביול 2014 17:39, "CN" <[1]cn...@fa...> כתב:
Please pardon me for asking client question. I have no idea
what else
place I can ask for help.
I prefer to place myscript.js as an external file than to
in-line it in
HTML page.
The URL passed to JsonRPC is determined in run time. As a
result,
myscript.js can not be coded as below because "/run/time/url"
is not
static. It is volatile:
var rpc=new JsonRPC('/run/time/url',['get'],[]);
rpc.get.on_result=function(r){ alert(r); }
rpc.get.on_error=function(e){ alert(e); }
I also tried this variation:
html:
<body onload="init('<%= url %>');rpc.get()">
myscript.js:
function init(url){ rpc=new JsonRPC(url,['get'],[]); }
rpc.get.on_result=function(r){ alert(r); } //variable "rpc" is
unknown
rpc.get.on_error=function(e){ alert(e); } //variable "rpc" is
unknown
However, my browser complains that variable "rpc" is unknown.
Would someone please help me out?
Regards,
CN
--
http://www.fastmail.fm - The way an email service should be
---------------------------------------------------------------
---------------
Want fast and easy access to all the code in your enterprise?
Index and
search up to 200,000 lines of code with a free copy of Black
Duck
Code Sight - the same software that powers the world's largest
code
search on Ohloh, the Black Duck Open Hub! Try it now.
[2]http://p.sf.net/sfu/bds
_______________________________________________
Cppcms-users mailing list
[3]Cpp...@li...
[4]https://lists.sourceforge.net/lists/listinfo/cppcms-users
---------------------------------------------------------------
---------------
Want fast and easy access to all the code in your enterprise?
Index and
search up to 200,000 lines of code with a free copy of Black
Duck
Code Sight - the same software that powers the world's largest
code
search on Ohloh, the Black Duck Open Hub! Try it now.
[5]http://p.sf.net/sfu/bds
_______________________________________________
Cppcms-users mailing list
[6]Cpp...@li...
[7]https://lists.sourceforge.net/lists/listinfo/cppcms-users
References
1. mailto:cn...@fa...
2. http://p.sf.net/sfu/bds
3. mailto:Cpp...@li...
4. https://lists.sourceforge.net/lists/listinfo/cppcms-users
5. http://p.sf.net/sfu/bds
6. mailto:Cpp...@li...
7. https://lists.sourceforge.net/lists/listinfo/cppcms-users
--
http://www.fastmail.fm - Access your email from home and the web
|