日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

067_VFPage中Js与controller交互方式(二) RemoteAction

發布時間:2025/4/5 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 067_VFPage中Js与controller交互方式(二) RemoteAction 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

上篇文章介紹了Toolkit API,是一種js的前臺寫法

同步調用格式:
sforce.connection.method("argument1","argument2",...);

異步調用格式:
sforce.connection.method("argument1","argument2",...,"callback_function");

此次介紹的內容仍為JS前臺的寫法,不過是和controller交互的,他不同與action對應的method,而是一種在js代碼中調用的controller 方法;

結構如下:

?

  • Use this to specify whether or not to escape the Apex method’s response. The default value is {escape: true}.

?callbackFunction接收方法調用的狀態和結果作為參數。

global with sharing class AccountRemoter {public String accountName { get; set; }public static Account cc{ get; set; }public AccountRemoter() { } // empty constructor@RemoteActionpublic static Account getAccount(String accountName) {cc = [SELECT Id, name,NumberOfEmployees FROM Account WHERE Name = :accountName];return cc;}}

  

<apex:page controller="AccountRemoter"> <script type="text/javascript">function getRemoteAccount() {var accountName = document.getElementById('acctSearch').value;Visualforce.remoting.Manager.invokeAction('{!$RemoteAction.AccountRemoter.getAccount}',accountName,function(result, event){if (event.status) {//alert(result); //console.log(result); console.log(event);// Get DOM IDs for HTML and Visualforce elements like thisdocument.getElementById('remoteAcctId').innerHTML = result.Iddocument.getElementById("{!$Component.block.blockSection.secondItem.acctNumEmployees}").innerHTML = result.NumberOfEmployees;} else if (event.type === 'exception') {document.getElementById("responseErrors").innerHTML =event.message + "<br/>\n<pre>" + event.where + "</pre>";} else {document.getElementById("responseErrors").innerHTML = event.message;}},{escape: true});} </script> <input id="acctSearch" type="text"/> <button οnclick="getRemoteAccount()">Get Account</button> <div id="responseErrors"></div><apex:pageBlock id="block"><apex:pageBlockSection id="blockSection" columns="2"><apex:pageBlockSectionItem id="firstItem"><span id="remoteAcctId"/></apex:pageBlockSectionItem><apex:pageBlockSectionItem id="secondItem"><apex:outputText id="acctNumEmployees"/></apex:pageBlockSectionItem></apex:pageBlockSection> </apex:pageBlock> </apex:page>

  

?

?

轉載于:https://www.cnblogs.com/bandariFang/p/9682154.html

總結

以上是生活随笔為你收集整理的067_VFPage中Js与controller交互方式(二) RemoteAction的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。