
由于不知道你是用什么方法或者框架 ,在这里只是介绍下jquery 和struts2 的反值
如果你想返回值给页面 你可以试试这种方法
在js 用
$getJSON("你的action连接" ,function(data){
alert(datamsg); //msg是在下面有说
});
后台Action
自己定义一个 xx
例:private String msg;
然后生成setting 合和 getting 方法
然后在你的action方法里面 赋值给 msg ; js才可以获取你想要返回msg的值
//------------------------
还有一点就是要在 struts 配置那是用json,因为返回的是json
<package name="struts" extends="json-default">
<action name="showmessage" class="xxxxx">
<result name="xx" type="json"></result>
</action>
</package>
>
添加进去代码以后,根据提示找到Controllerclassphp,手动添加如下代码:
/
获取当前Action名称
@access protected
/
protected function getActionName() {
if(empty($this->name)) {
// 获取Action名称
$offset=strrpos(get_class($this), '\\', -10); // 从尾部第 10 个位置开始查找
$this->name = substr(get_class($this),$offset+1,-10);
}
return $this->name;
}
复制代码
然后在可以在控制器中使用routesphp方法获取控制器名称了
你好:
action可能是从其他页面传递过来的, 也可能是本页的参数;
本页设置参数:requestsetAttribute(xxx,xxx);
其他页面传递:xxxjspaction=xxx;
希望可以帮助到你;
以上就是关于jquery调用了action的方法全部的内容,包括:jquery调用了action的方法、请问strut2 中的action如何获取 <a href="<%=basePath%>info/department.actioncurrentPage 值、如何在laravel routes.php里获取控制器和action名称等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)