日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

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

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

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

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

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

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

結構如下:

?

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

?callbackFunction接收方法調(diào)用的狀態(tài)和結果作為參數(shù)。

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的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。