I wrote one function recently.My JavaScript function calls CppCMS web method
via JSONP.Here is one example.
client side in html:
<script type="text/javascript">
function save_email(){
var message=document.getElementById("email_content").value;
$.ajax({
"url": "http://www.cmlelectronics.com:8080/save_email?content=
"+message+"&callback=?",
type:"get",
dataType:"jsonp",
jsonp:"callback",
success:function(data){
alert(data.result);
},
error:function(err){
alert(err.result);
},
complete: function(msg){
}
});
}
</script>
Server side:
hello::hello(cppcms::service &srv):cppcms::application(srv){
,..
dispatcher().assign("/save_email?(.+)" , &hello::save_email , this , 3);
...
}
//test url http://IP/save_email?content=...&callback=jsonp
void hello::save_message(std::string str){
BOOSTER_NOTICE("hello") << "Enter save_message function";
std::string wrapper_function = request().get("callback");
try{
std::string content = request().get("content");
auto_ptr<cppdb::session> session =
sql_session_factory::create_session();
cppdb::statement stat;
//do something
stat.exec();
response().out() << wrapper_function <<'(';
response().out()<<"{result:\"Your message has been saved
successfully,please wait!\"}";
response().out() << ')';
}catch(std::exception &ex){
response().out() << wrapper_function <<'(';
response().out()<<"{result:\""<<ex.what()<<"\"}";
response().out() << ')';
}
}
陈抒
Best regards
http://blog.csdn.net/sheismylife
On Fri, Oct 28, 2011 at 9:13 AM, Richard Catlin
<ric...@gm...>wrote:
> Is there a sample of how to integrate cppcms and jQuery?
>
> In general are your widgets just html based or is there some javascript
> embedded in the widget? Is so, what library and which class would be the
> best for me to look at as an example of how to integrate cppcms with
> html/javascript? Is there some design pattern you are following?
>
> Richard Catlin
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> ------------------------------------------------------------------------------
> The demand for IT networking professionals continues to grow, and the
> demand for specialized networking skills is growing even more rapidly.
> Take a complimentary Learning@Cisco Self-Assessment and learn
> about Cisco certifications, training, and career opportunities.
> http://p.sf.net/sfu/cisco-dev2dev
> _______________________________________________
> Cppcms-users mailing list
> Cpp...@li...
> https://lists.sourceforge.net/lists/listinfo/cppcms-users
>
|