在visualforce中从javascript调用控制器方法
作者:互联网
如何在没有任何onclick事件发生的情况下从VisualForce页面调用控制器方法?
我的VisualForce页面就像
<apex:page standardController="Account">
<script>
/* Here i need to call a controller class with out any onclick event. It should load by itselef */
</script>
</apex:page>
我的控制器类就像
public class OrderPadController {
/* this will be the constructor */
public PageReference openPage() {
PageReference newpage = new Pagereference('/apex'+'/pagetoopen'+'?aid='+a.id);
openorderpadembed.setRedirect(false);
return openorderpadembed;
}
从我的VisualForce页面,我需要调用openPage()方法.
请帮帮我
解决方法:
您可以通过以下方式使用JavaScript Remoting for Apex Controllers:
<apex:page standardController="Account" extensions="OrderPadController">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
window.$j = jQuery.noConflict();
$j( document ).ready(function() {
OrderPadController.openPage(function(result, event){
console.log(result);
window.open(result,"_self");
});
});
</script>
</apex:page>
public class OrderPadController {
//
@remoteAction
public PageReference openPage() {
PageReference newpage = NEW Pagereference('/apex' + '/pagetoopen' + '?aid=' + a.id);
openorderpadembed.setRedirect(false);
return openorderpadembed;
}
}
标签:javascript,salesforce,visualforce 来源: https://codeday.me/bug/20190831/1773628.html